Access to Shared folder from asp.net

Discussion in 'ASP .Net' started by =?Utf-8?B?SWJyYWhpbS4=?=, Jul 6, 2006.

  1. Hello,

    How can I access a Shared Folder of the Server by using the following control.

    1. I need to download files from c:\resumes folde by using the following;

    <asp:HyperLink
    NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'

    a. FilePath is a database field holding the value "c:\resumes\myresume.doc"

    b. NavigateUrl will prefix the virtual path & then the filepath.

    Any thoughts are welcome
     
    =?Utf-8?B?SWJyYWhpbS4=?=, Jul 6, 2006
    #1
    1. Advertising

  2. I'm doing something similar on a web application. For various reasons, I
    pulled a copy of the document (a PDF) into a temporary directory under the
    website that I associated with a particular user. When the user's session
    expires (or when they log off), I clear their cache. For my requirements and
    my application, this was the best choice.
    You might want to look at streaming the document directly into a webpage
    rather than allowing anonymous users access to the resume directory. Giving
    anon users access to a shared folder is a security problem. At least make
    sure the user account under which access will be granted (aspnet or whatever
    in your case) has read-only access...

    "Ibrahim." wrote:

    > Hello,
    >
    > How can I access a Shared Folder of the Server by using the following control.
    >
    > 1. I need to download files from c:\resumes folde by using the following;
    >
    > <asp:HyperLink
    > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    >
    > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    >
    > b. NavigateUrl will prefix the virtual path & then the filepath.
    >
    > Any thoughts are welcome
    >
    >
     
    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Jul 6, 2006
    #2
    1. Advertising

  3. Instead of using a Hyperlink that directly links to the shared folder, use a
    button (or a buttoncolumn in a datagrid). On the server side while processing
    the click event of that button you can have the asp.net account read the
    resume and write to the web page, e.g.

    Response.Clear();
    Response.ContentType = "application/vnd.ms-word";
    HttpContext.Current.Response.AddHeader("content-disposition",
    "attachment;filename=test.doc");
    Response.WriteFile (@"c:\Resumes\myresume.doc");

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Ibrahim." wrote:

    > Hello,
    >
    > How can I access a Shared Folder of the Server by using the following control.
    >
    > 1. I need to download files from c:\resumes folde by using the following;
    >
    > <asp:HyperLink
    > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    >
    > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    >
    > b. NavigateUrl will prefix the virtual path & then the filepath.
    >
    > Any thoughts are welcome
    >
    >
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Jul 6, 2006
    #3
  4. Hi,

    Thanks a lot for your reply.

    Yes, your solutions works fine, but going futher How can I dynamically send
    the full file name(with the path) to the click event of LinkButton.

    My case is that the file names are programatically read from the repository
    & binded to the Linkbutton, so upon the click event the associated files
    names are downloaded..isnt?

    Thanks,



    "Phillip Williams" wrote:

    > Instead of using a Hyperlink that directly links to the shared folder, use a
    > button (or a buttoncolumn in a datagrid). On the server side while processing
    > the click event of that button you can have the asp.net account read the
    > resume and write to the web page, e.g.
    >
    > Response.Clear();
    > Response.ContentType = "application/vnd.ms-word";
    > HttpContext.Current.Response.AddHeader("content-disposition",
    > "attachment;filename=test.doc");
    > Response.WriteFile (@"c:\Resumes\myresume.doc");
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Ibrahim." wrote:
    >
    > > Hello,
    > >
    > > How can I access a Shared Folder of the Server by using the following control.
    > >
    > > 1. I need to download files from c:\resumes folde by using the following;
    > >
    > > <asp:HyperLink
    > > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    > >
    > > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    > >
    > > b. NavigateUrl will prefix the virtual path & then the filepath.
    > >
    > > Any thoughts are welcome
    > >
    > >
     
    =?Utf-8?B?SWJyYWhpbS4=?=, Jul 7, 2006
    #4
  5. Hi Ibrahim,

    The LinkButton allows you to use a CommandArgument, e.g.

    <ItemTemplate>
    <asp:LinkButton Runat="server" ID="lnkResume"
    CommandArgument ='<%#DataBinder.Eval(Container.DataItem,"FilePath"")%>'
    CommandName ="Navigate"
    Text='<%#DataBinder.Eval(Container.DataItem,"UserName","Resume for
    {0}")%>'>
    </asp:LinkButton>
    </ItemTemplate>

    Then while handling the ItemCommand event of the DataGrid (or the RowCommand
    of the GridView) you would get the CommandArgument like this:

    private void datagrid1_ItemCommand(object source, DataGridCommandEventArgs e)
    {
    string strLink = e.CommandArgument.ToString ();
    // if strLink has only the file name without the path
    // then uncomment the following line
    // strLink = Server.MapPath (strLink);
    Response.Clear();
    Response.ContentType = "application/vnd.ms-word";
    HttpContext.Current.Response.AddHeader("content-disposition",
    "attachment;filename=Resume.doc");
    Response.WriteFile (strLink);
    }
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Ibrahim." wrote:

    > Hi,
    >
    > Thanks a lot for your reply.
    >
    > Yes, your solutions works fine, but going futher How can I dynamically send
    > the full file name(with the path) to the click event of LinkButton.
    >
    > My case is that the file names are programatically read from the repository
    > & binded to the Linkbutton, so upon the click event the associated files
    > names are downloaded..isnt?
    >
    > Thanks,
    >
    >
    >
    > "Phillip Williams" wrote:
    >
    > > Instead of using a Hyperlink that directly links to the shared folder, use a
    > > button (or a buttoncolumn in a datagrid). On the server side while processing
    > > the click event of that button you can have the asp.net account read the
    > > resume and write to the web page, e.g.
    > >
    > > Response.Clear();
    > > Response.ContentType = "application/vnd.ms-word";
    > > HttpContext.Current.Response.AddHeader("content-disposition",
    > > "attachment;filename=test.doc");
    > > Response.WriteFile (@"c:\Resumes\myresume.doc");
    > >
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "Ibrahim." wrote:
    > >
    > > > Hello,
    > > >
    > > > How can I access a Shared Folder of the Server by using the following control.
    > > >
    > > > 1. I need to download files from c:\resumes folde by using the following;
    > > >
    > > > <asp:HyperLink
    > > > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    > > >
    > > > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    > > >
    > > > b. NavigateUrl will prefix the virtual path & then the filepath.
    > > >
    > > > Any thoughts are welcome
    > > >
    > > >
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Jul 7, 2006
    #5
  6. Hi Williams,

    Thanks a lot for your great deal of work. I was looking for the solution who
    have just provided, it really has helped.

    In case I require further corresponding with you in future, how shall I get
    in touch ?

    Thanks once again.



    "Phillip Williams" wrote:

    > Hi Ibrahim,
    >
    > The LinkButton allows you to use a CommandArgument, e.g.
    >
    > <ItemTemplate>
    > <asp:LinkButton Runat="server" ID="lnkResume"
    > CommandArgument ='<%#DataBinder.Eval(Container.DataItem,"FilePath"")%>'
    > CommandName ="Navigate"
    > Text='<%#DataBinder.Eval(Container.DataItem,"UserName","Resume for
    > {0}")%>'>
    > </asp:LinkButton>
    > </ItemTemplate>
    >
    > Then while handling the ItemCommand event of the DataGrid (or the RowCommand
    > of the GridView) you would get the CommandArgument like this:
    >
    > private void datagrid1_ItemCommand(object source, DataGridCommandEventArgs e)
    > {
    > string strLink = e.CommandArgument.ToString ();
    > // if strLink has only the file name without the path
    > // then uncomment the following line
    > // strLink = Server.MapPath (strLink);
    > Response.Clear();
    > Response.ContentType = "application/vnd.ms-word";
    > HttpContext.Current.Response.AddHeader("content-disposition",
    > "attachment;filename=Resume.doc");
    > Response.WriteFile (strLink);
    > }
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Ibrahim." wrote:
    >
    > > Hi,
    > >
    > > Thanks a lot for your reply.
    > >
    > > Yes, your solutions works fine, but going futher How can I dynamically send
    > > the full file name(with the path) to the click event of LinkButton.
    > >
    > > My case is that the file names are programatically read from the repository
    > > & binded to the Linkbutton, so upon the click event the associated files
    > > names are downloaded..isnt?
    > >
    > > Thanks,
    > >
    > >
    > >
    > > "Phillip Williams" wrote:
    > >
    > > > Instead of using a Hyperlink that directly links to the shared folder, use a
    > > > button (or a buttoncolumn in a datagrid). On the server side while processing
    > > > the click event of that button you can have the asp.net account read the
    > > > resume and write to the web page, e.g.
    > > >
    > > > Response.Clear();
    > > > Response.ContentType = "application/vnd.ms-word";
    > > > HttpContext.Current.Response.AddHeader("content-disposition",
    > > > "attachment;filename=test.doc");
    > > > Response.WriteFile (@"c:\Resumes\myresume.doc");
    > > >
    > > > --
    > > > HTH,
    > > > Phillip Williams
    > > > http://www.societopia.net
    > > > http://www.webswapp.com
    > > >
    > > >
    > > > "Ibrahim." wrote:
    > > >
    > > > > Hello,
    > > > >
    > > > > How can I access a Shared Folder of the Server by using the following control.
    > > > >
    > > > > 1. I need to download files from c:\resumes folde by using the following;
    > > > >
    > > > > <asp:HyperLink
    > > > > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    > > > >
    > > > > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    > > > >
    > > > > b. NavigateUrl will prefix the virtual path & then the filepath.
    > > > >
    > > > > Any thoughts are welcome
    > > > >
    > > > >
     
    =?Utf-8?B?SWJyYWhpbS4=?=, Jul 7, 2006
    #6
  7. Hi Ibrahim,

    You are welcome.

    If you have a technical question on which you are looking for a
    free-discussion then continue to post on the newsgroup and any one from the
    participants on this newsgroup would answer when they have free time. For
    non-technical questions, you can write directly to me on my email address (as
    shown on my website).

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Ibrahim." wrote:

    > Hi Williams,
    >
    > Thanks a lot for your great deal of work. I was looking for the solution who
    > have just provided, it really has helped.
    >
    > In case I require further corresponding with you in future, how shall I get
    > in touch ?
    >
    > Thanks once again.
    >
    >
    >
    > "Phillip Williams" wrote:
    >
    > > Hi Ibrahim,
    > >
    > > The LinkButton allows you to use a CommandArgument, e.g.
    > >
    > > <ItemTemplate>
    > > <asp:LinkButton Runat="server" ID="lnkResume"
    > > CommandArgument ='<%#DataBinder.Eval(Container.DataItem,"FilePath"")%>'
    > > CommandName ="Navigate"
    > > Text='<%#DataBinder.Eval(Container.DataItem,"UserName","Resume for
    > > {0}")%>'>
    > > </asp:LinkButton>
    > > </ItemTemplate>
    > >
    > > Then while handling the ItemCommand event of the DataGrid (or the RowCommand
    > > of the GridView) you would get the CommandArgument like this:
    > >
    > > private void datagrid1_ItemCommand(object source, DataGridCommandEventArgs e)
    > > {
    > > string strLink = e.CommandArgument.ToString ();
    > > // if strLink has only the file name without the path
    > > // then uncomment the following line
    > > // strLink = Server.MapPath (strLink);
    > > Response.Clear();
    > > Response.ContentType = "application/vnd.ms-word";
    > > HttpContext.Current.Response.AddHeader("content-disposition",
    > > "attachment;filename=Resume.doc");
    > > Response.WriteFile (strLink);
    > > }
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "Ibrahim." wrote:
    > >
    > > > Hi,
    > > >
    > > > Thanks a lot for your reply.
    > > >
    > > > Yes, your solutions works fine, but going futher How can I dynamically send
    > > > the full file name(with the path) to the click event of LinkButton.
    > > >
    > > > My case is that the file names are programatically read from the repository
    > > > & binded to the Linkbutton, so upon the click event the associated files
    > > > names are downloaded..isnt?
    > > >
    > > > Thanks,
    > > >
    > > >
    > > >
    > > > "Phillip Williams" wrote:
    > > >
    > > > > Instead of using a Hyperlink that directly links to the shared folder, use a
    > > > > button (or a buttoncolumn in a datagrid). On the server side while processing
    > > > > the click event of that button you can have the asp.net account read the
    > > > > resume and write to the web page, e.g.
    > > > >
    > > > > Response.Clear();
    > > > > Response.ContentType = "application/vnd.ms-word";
    > > > > HttpContext.Current.Response.AddHeader("content-disposition",
    > > > > "attachment;filename=test.doc");
    > > > > Response.WriteFile (@"c:\Resumes\myresume.doc");
    > > > >
    > > > > --
    > > > > HTH,
    > > > > Phillip Williams
    > > > > http://www.societopia.net
    > > > > http://www.webswapp.com
    > > > >
    > > > >
    > > > > "Ibrahim." wrote:
    > > > >
    > > > > > Hello,
    > > > > >
    > > > > > How can I access a Shared Folder of the Server by using the following control.
    > > > > >
    > > > > > 1. I need to download files from c:\resumes folde by using the following;
    > > > > >
    > > > > > <asp:HyperLink
    > > > > > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    > > > > >
    > > > > > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    > > > > >
    > > > > > b. NavigateUrl will prefix the virtual path & then the filepath.
    > > > > >
    > > > > > Any thoughts are welcome
    > > > > >
    > > > > >
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Jul 7, 2006
    #7
  8. hi,

    I'm using the following code for the LINKbutton, but get file damaged error
    at the client side; do i have to use proper encoding?, the file opens
    correctly when i access it directly.

    Dim myFileInfo As New FileInfo(sender.CommandArgument)
    Dim myFilePath As String =
    System.Configuration.ConfigurationManager.AppSettings("UploadFolder").ToString & "\" & myFileInfo.Name
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.ClearHeaders()
    HttpContext.Current.Response.ClearContent()

    Response.ContentType = "application/pdf"
    HttpContext.Current.Response.AppendHeader("content-disposition",
    "attachment;filename=" & myFileInfo.Name)
    Response.WriteFile(myFilePath)
    Response.End()

    Regards,





    "Phillip Williams" wrote:

    > Hi Ibrahim,
    >
    > You are welcome.
    >
    > If you have a technical question on which you are looking for a
    > free-discussion then continue to post on the newsgroup and any one from the
    > participants on this newsgroup would answer when they have free time. For
    > non-technical questions, you can write directly to me on my email address (as
    > shown on my website).
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Ibrahim." wrote:
    >
    > > Hi Williams,
    > >
    > > Thanks a lot for your great deal of work. I was looking for the solution who
    > > have just provided, it really has helped.
    > >
    > > In case I require further corresponding with you in future, how shall I get
    > > in touch ?
    > >
    > > Thanks once again.
    > >
    > >
    > >
    > > "Phillip Williams" wrote:
    > >
    > > > Hi Ibrahim,
    > > >
    > > > The LinkButton allows you to use a CommandArgument, e.g.
    > > >
    > > > <ItemTemplate>
    > > > <asp:LinkButton Runat="server" ID="lnkResume"
    > > > CommandArgument ='<%#DataBinder.Eval(Container.DataItem,"FilePath"")%>'
    > > > CommandName ="Navigate"
    > > > Text='<%#DataBinder.Eval(Container.DataItem,"UserName","Resume for
    > > > {0}")%>'>
    > > > </asp:LinkButton>
    > > > </ItemTemplate>
    > > >
    > > > Then while handling the ItemCommand event of the DataGrid (or the RowCommand
    > > > of the GridView) you would get the CommandArgument like this:
    > > >
    > > > private void datagrid1_ItemCommand(object source, DataGridCommandEventArgs e)
    > > > {
    > > > string strLink = e.CommandArgument.ToString ();
    > > > // if strLink has only the file name without the path
    > > > // then uncomment the following line
    > > > // strLink = Server.MapPath (strLink);
    > > > Response.Clear();
    > > > Response.ContentType = "application/vnd.ms-word";
    > > > HttpContext.Current.Response.AddHeader("content-disposition",
    > > > "attachment;filename=Resume.doc");
    > > > Response.WriteFile (strLink);
    > > > }
    > > > --
    > > > HTH,
    > > > Phillip Williams
    > > > http://www.societopia.net
    > > > http://www.webswapp.com
    > > >
    > > >
    > > > "Ibrahim." wrote:
    > > >
    > > > > Hi,
    > > > >
    > > > > Thanks a lot for your reply.
    > > > >
    > > > > Yes, your solutions works fine, but going futher How can I dynamically send
    > > > > the full file name(with the path) to the click event of LinkButton.
    > > > >
    > > > > My case is that the file names are programatically read from the repository
    > > > > & binded to the Linkbutton, so upon the click event the associated files
    > > > > names are downloaded..isnt?
    > > > >
    > > > > Thanks,
    > > > >
    > > > >
    > > > >
    > > > > "Phillip Williams" wrote:
    > > > >
    > > > > > Instead of using a Hyperlink that directly links to the shared folder, use a
    > > > > > button (or a buttoncolumn in a datagrid). On the server side while processing
    > > > > > the click event of that button you can have the asp.net account read the
    > > > > > resume and write to the web page, e.g.
    > > > > >
    > > > > > Response.Clear();
    > > > > > Response.ContentType = "application/vnd.ms-word";
    > > > > > HttpContext.Current.Response.AddHeader("content-disposition",
    > > > > > "attachment;filename=test.doc");
    > > > > > Response.WriteFile (@"c:\Resumes\myresume.doc");
    > > > > >
    > > > > > --
    > > > > > HTH,
    > > > > > Phillip Williams
    > > > > > http://www.societopia.net
    > > > > > http://www.webswapp.com
    > > > > >
    > > > > >
    > > > > > "Ibrahim." wrote:
    > > > > >
    > > > > > > Hello,
    > > > > > >
    > > > > > > How can I access a Shared Folder of the Server by using the following control.
    > > > > > >
    > > > > > > 1. I need to download files from c:\resumes folde by using the following;
    > > > > > >
    > > > > > > <asp:HyperLink
    > > > > > > NavigateUrl='<%#DataBinder.Eval(Container.DataItem,"FilePath") %>'
    > > > > > >
    > > > > > > a. FilePath is a database field holding the value "c:\resumes\myresume.doc"
    > > > > > >
    > > > > > > b. NavigateUrl will prefix the virtual path & then the filepath.
    > > > > > >
    > > > > > > Any thoughts are welcome
    > > > > > >
    > > > > > >
     
    =?Utf-8?B?SWJyYWhpbS4=?=, Aug 8, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?V2F5ZGVXeWF0dA==?=

    ASP.Net Bin folder on shared drive

    =?Utf-8?B?V2F5ZGVXeWF0dA==?=, Sep 18, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    393
    =?Utf-8?B?V2F5ZGVXeWF0dA==?=
    Sep 18, 2004
  2. mmb
    Replies:
    0
    Views:
    196
  3. shared folder access

    , Oct 15, 2003, in forum: ASP .Net Security
    Replies:
    4
    Views:
    240
    sandy
    Oct 17, 2003
  4. James
    Replies:
    2
    Views:
    145
    Ray at
    Aug 10, 2004
  5. Sebastian Scholz

    win32 - access shared folder

    Sebastian Scholz, Jun 29, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    199
    MrReallyVeryNice
    Jun 30, 2004
Loading...

Share This Page