I am trying to download documents from my ASP.NET 2.0 website

Discussion in 'ASP.NET 2.0' started by wkirkman3ne, Oct 3, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I am trying to download documents from my ASP.NET 2.0 website.
    I am getting the following message:

    Server Error in '/' Application.
    Could not find file 'E:\web\wkirkman3ne\htdocs\projects\Web_WilliamKirkman3.doc'.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.IO.FileNotFoundException: Could not find file 'E:\web\wkirkman3ne\htdocs\projects\Web_WilliamKirkman3.doc'.

    Source Error:

    Line 48: if (type != "")
    Line 49: Response.ContentType = type;
    Line 50: Response.WriteFile(name);
    Line 51: Response.End();
    Line 52: }


    Source File: e:\web\wkirkman3ne\htdocs\resume.aspx.cs Line: 50

    Stack Trace:

    [FileNotFoundException: Could not find file 'E:\web\wkirkman3ne\htdocs\projects\Web_WilliamKirkman3.doc'.]
    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +1971213
    System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +114
    System.Web.HttpResponse.WriteFile(String filename, Boolean readIntoMemory) +79
    System.Web.HttpResponse.WriteFile(String filename) +6
    resume.LinkButton1_Click(Object sender, EventArgs e) in e:\web\wkirkman3ne\htdocs\resume.aspx.cs:50
    System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +105
    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +107
    System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


    Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

    Here is the code I am using on my button click event:

    string name = "\\projects\\Web_WilliamKirkman3.doc";

    string ext = ".doc";
    string type = "";
    // set known types based on file extension
    if (ext != null)
    {
    switch (ext.ToLower())
    {

    case ".doc":
    type = "Application/msword";
    break;
    }
    }
    Response.AppendHeader("content-disposition","attachment; filename=" + name);

    if (type != "")
    Response.ContentType = type;
    Response.WriteFile(name);
    Response.End();

    The paths do not match according to the error message yet the projects directory is in my site directory structure with the
    word doc in the given directory. I can see the path is remapped on the discount asp.net servers which I would expect but
    I would have thought the specific path for the name would override the path.

    Post Edited By Moderator (mjp [DASP]) : 11/2/2007 8:59:35 PM GMT
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    I am not sure I understand.. is the file located at \projects\Web_WilliamKirkman3.doc?

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Bruce,
    Thanks for replying. Yes, off the root directory I have a projects directory which contains the file. I receive the above error when I have the file in the projects directory. I moved it the the App_Data directory and then changed the hard coded name and it works. Just curious as to why it fails in the projects directory.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page