Error when uploading file

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Error when uploading file

    I am trying to write code to allow my users to upload a file. The code I am
    using is as follows:

    Dim upfilename As String = ""

    If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength > 0
    Then

    Dim dir As String() =
    fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())

    upfilename = dir(dir.GetUpperBound(0))

    fileDetails.PostedFile.SaveAs(Server.MapPath("/eventdetails/") & upfilename)

    End If


    When I run this code, I recieve an error similar to the following:

    Server Error in '/lvbeporgtest' Application.
    --------------------------------------------------------------------------------

    Could not find a part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    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.DirectoryNotFoundException: Could not find a
    part of the path "D:\Webdev_Site\eventdetails\resume.pdf".

    Source Error:

    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of the
    exception can be identified using the exception stack trace below.

    Stack Trace:

    [DirectoryNotFoundException: Could not find a part of the path
    "D:\Webdev_Site\eventdetails\resume.pdf".]
    System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
    bFromProxy) +888
    System.IO.FileStream..ctor(String path, FileMode mode) +52
    System.Web.HttpPostedFile.SaveAs(String filename) +48
    createevent.btnSubmit_Click(Object sender, EventArgs e) in C:\Documents
    and Settings\Nathan
    Sokalski\VSWebCache\[url]www.webdevlccc.com\lvbeporgtest\createevent.aspx.v b:114[/url]
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    eventArgument) +57
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    sourceControl, String eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    System.Web.UI.Page.ProcessRequestMain() +1292



    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET
    Version:1.1.4322.2300


    I have used this same code before without any problems, what do I need to do
    differently?

    --
    Nathan Sokalski
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]


    Nathan Sokalski Guest

  2. Similar Questions and Discussions

    1. Error uploading file
      If you have a slow connection, uploading 2.8 MB might take longer than 300 seconds. You could try setting the max_execution_time to 0 (unlimited)...
    2. Web Service: Uploading files and setting file security on a file server
      I have written a web service that provides the following methods: UploadFile SetNTFSSecurity Their purpose is to allow a user to Upload a file...
    3. #25563 [Opn->Bgs]: error uploading file
      ID: 25563 Updated by: iliaa@php.net Reported By: t_lace at yahoo dot com -Status: Open +Status: ...
    4. #25563 [NEW]: error uploading file
      From: t_lace at yahoo dot com Operating system: linux PHP version: 4.3.2 PHP Bug Type: Filesystem function related Bug...
    5. uploading a file
      Hi all! I have used code below to upload file but I receive an error on last row of code telling me ( method not allowed ) is it about iis or...
  3. #2

    Default Re: Error when uploading file

    Is the file located there?
    can you copy that path and get to your resume.pdf?

    if so are you using windows 2003 server, if you are make sure that pdf is
    allowed to be served in IIS.

    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    news:eQe$BCnrFHA.2596@TK2MSFTNGP09.phx.gbl...
    >I am trying to write code to allow my users to upload a file. The code I am
    >using is as follows:
    >
    > Dim upfilename As String = ""
    >
    > If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength >
    > 0 Then
    >
    > Dim dir As String() =
    > fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())
    >
    > upfilename = dir(dir.GetUpperBound(0))
    >
    > fileDetails.PostedFile.SaveAs(Server.MapPath("/eventdetails/") &
    > upfilename)
    >
    > End If
    >
    >
    > When I run this code, I recieve an error similar to the following:
    >
    > Server Error in '/lvbeporgtest' Application.
    > --------------------------------------------------------------------------------
    >
    > Could not find a part of the path
    > "D:\Webdev_Site\eventdetails\resume.pdf".
    > 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.DirectoryNotFoundException: Could not find a
    > part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    >
    > Source Error:
    >
    > An unhandled exception was generated during the execution of the
    > current web request. Information regarding the origin and location of the
    > exception can be identified using the exception stack trace below.
    >
    > Stack Trace:
    >
    > [DirectoryNotFoundException: Could not find a part of the path
    > "D:\Webdev_Site\eventdetails\resume.pdf".]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    > access, FileShare share, Int32 bufferSize, Boolean useAsync, String
    > msgPath, Boolean bFromProxy) +888
    > System.IO.FileStream..ctor(String path, FileMode mode) +52
    > System.Web.HttpPostedFile.SaveAs(String filename) +48
    > createevent.btnSubmit_Click(Object sender, EventArgs e) in C:\Documents
    > and Settings\Nathan
    > Sokalski\VSWebCache\[url]www.webdevlccc.com\lvbeporgtest\createevent.aspx.v b:114[/url]
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    >
    > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    > eventArgument) +57
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    > sourceControl, String eventArgument) +18
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    > System.Web.UI.Page.ProcessRequestMain() +1292
    >
    >
    >
    > --------------------------------------------------------------------------------
    > Version Information: Microsoft .NET Framework Version:1.1.4322.2300;
    > ASP.NET Version:1.1.4322.2300
    >
    >
    > I have used this same code before without any problems, what do I need to
    > do differently?
    >
    > --
    > Nathan Sokalski
    > [email]njsokalski@hotmail.com[/email]
    > [url]http://www.nathansokalski.com/[/url]
    >

    Chris Guest

  4. #3

    Default Re: Error when uploading file

    What do you mean is the file located there? I am uploading the file, not
    downloading it, therefore, I do not expect it to be on the server while this
    code is being executed. Thanks.
    --
    Nathan Sokalski
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]

    "Chris" <ccalzaretta@hotmail.com> wrote in message
    news:%23LZXConrFHA.2272@TK2MSFTNGP11.phx.gbl...
    > Is the file located there?
    > can you copy that path and get to your resume.pdf?
    >
    > if so are you using windows 2003 server, if you are make sure that pdf is
    > allowed to be served in IIS.
    >
    > "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    > news:eQe$BCnrFHA.2596@TK2MSFTNGP09.phx.gbl...
    >>I am trying to write code to allow my users to upload a file. The code I
    >>am using is as follows:
    >>
    >> Dim upfilename As String = ""
    >>
    >> If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength >
    >> 0 Then
    >>
    >> Dim dir As String() =
    >> fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())
    >>
    >> upfilename = dir(dir.GetUpperBound(0))
    >>
    >> fileDetails.PostedFile.SaveAs(Server.MapPath("/eventdetails/") &
    >> upfilename)
    >>
    >> End If
    >>
    >>
    >> When I run this code, I recieve an error similar to the following:
    >>
    >> Server Error in '/lvbeporgtest' Application.
    >> --------------------------------------------------------------------------------
    >>
    >> Could not find a part of the path
    >> "D:\Webdev_Site\eventdetails\resume.pdf".
    >> 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.DirectoryNotFoundException: Could not find a
    >> part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    >>
    >> Source Error:
    >>
    >> An unhandled exception was generated during the execution of the
    >> current web request. Information regarding the origin and location of the
    >> exception can be identified using the exception stack trace below.
    >>
    >> Stack Trace:
    >>
    >> [DirectoryNotFoundException: Could not find a part of the path
    >> "D:\Webdev_Site\eventdetails\resume.pdf".]
    >> System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
    >> System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    >> access, FileShare share, Int32 bufferSize, Boolean useAsync, String
    >> msgPath, Boolean bFromProxy) +888
    >> System.IO.FileStream..ctor(String path, FileMode mode) +52
    >> System.Web.HttpPostedFile.SaveAs(String filename) +48
    >> createevent.btnSubmit_Click(Object sender, EventArgs e) in C:\Documents
    >> and Settings\Nathan
    >> Sokalski\VSWebCache\[url]www.webdevlccc.com\lvbeporgtest\createevent.aspx.v b:114[/url]
    >> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    >>
    >> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    >> eventArgument) +57
    >> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    >> sourceControl, String eventArgument) +18
    >> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    >> System.Web.UI.Page.ProcessRequestMain() +1292
    >>
    >>
    >>
    >> --------------------------------------------------------------------------------
    >> Version Information: Microsoft .NET Framework Version:1.1.4322.2300;
    >> ASP.NET Version:1.1.4322.2300
    >>
    >>
    >> I have used this same code before without any problems, what do I need to
    >> do differently?
    >>
    >> --
    >> Nathan Sokalski
    >> [email]njsokalski@hotmail.com[/email]
    >> [url]http://www.nathansokalski.com/[/url]
    >>
    >
    >

    Nathan Sokalski Guest

  5. #4

    Default Re: Error when uploading file

    The error you stated is saying the file is not there. So take is as you
    will.
    Eather the file your trying to upload cant be found,
    or the file that you uploaded did not really upload. I am unsure I would
    take alook at the mappath


    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    news:OS6fa3orFHA.1252@TK2MSFTNGP09.phx.gbl...
    > What do you mean is the file located there? I am uploading the file, not
    > downloading it, therefore, I do not expect it to be on the server while
    > this code is being executed. Thanks.
    > --
    > Nathan Sokalski
    > [email]njsokalski@hotmail.com[/email]
    > [url]http://www.nathansokalski.com/[/url]
    >
    > "Chris" <ccalzaretta@hotmail.com> wrote in message
    > news:%23LZXConrFHA.2272@TK2MSFTNGP11.phx.gbl...
    >> Is the file located there?
    >> can you copy that path and get to your resume.pdf?
    >>
    >> if so are you using windows 2003 server, if you are make sure that pdf is
    >> allowed to be served in IIS.
    >>
    >> "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    >> news:eQe$BCnrFHA.2596@TK2MSFTNGP09.phx.gbl...
    >>>I am trying to write code to allow my users to upload a file. The code I
    >>>am using is as follows:
    >>>
    >>> Dim upfilename As String = ""
    >>>
    >>> If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength
    >>> > 0 Then
    >>>
    >>> Dim dir As String() =
    >>> fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())
    >>>
    >>> upfilename = dir(dir.GetUpperBound(0))
    >>>
    >>> fileDetails.PostedFile.SaveAs(Server.MapPath("/eventdetails/") &
    >>> upfilename)
    >>>
    >>> End If
    >>>
    >>>
    >>> When I run this code, I recieve an error similar to the following:
    >>>
    >>> Server Error in '/lvbeporgtest' Application.
    >>> --------------------------------------------------------------------------------
    >>>
    >>> Could not find a part of the path
    >>> "D:\Webdev_Site\eventdetails\resume.pdf".
    >>> 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.DirectoryNotFoundException: Could not find
    >>> a part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    >>>
    >>> Source Error:
    >>>
    >>> An unhandled exception was generated during the execution of the
    >>> current web request. Information regarding the origin and location of
    >>> the exception can be identified using the exception stack trace below.
    >>>
    >>> Stack Trace:
    >>>
    >>> [DirectoryNotFoundException: Could not find a part of the path
    >>> "D:\Webdev_Site\eventdetails\resume.pdf".]
    >>> System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
    >>> System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    >>> access, FileShare share, Int32 bufferSize, Boolean useAsync, String
    >>> msgPath, Boolean bFromProxy) +888
    >>> System.IO.FileStream..ctor(String path, FileMode mode) +52
    >>> System.Web.HttpPostedFile.SaveAs(String filename) +48
    >>> createevent.btnSubmit_Click(Object sender, EventArgs e) in
    >>> C:\Documents and Settings\Nathan
    >>> Sokalski\VSWebCache\[url]www.webdevlccc.com\lvbeporgtest\createevent.aspx.v b:114[/url]
    >>> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    >>>
    >>> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    >>> eventArgument) +57
    >>> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    >>> sourceControl, String eventArgument) +18
    >>> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
    >>> +33
    >>> System.Web.UI.Page.ProcessRequestMain() +1292
    >>>
    >>>
    >>>
    >>> --------------------------------------------------------------------------------
    >>> Version Information: Microsoft .NET Framework Version:1.1.4322.2300;
    >>> ASP.NET Version:1.1.4322.2300
    >>>
    >>>
    >>> I have used this same code before without any problems, what do I need
    >>> to do differently?
    >>>
    >>> --
    >>> Nathan Sokalski
    >>> [email]njsokalski@hotmail.com[/email]
    >>> [url]http://www.nathansokalski.com/[/url]
    >>>
    >>
    >>
    >
    >

    Chris Guest

  6. #5

    Default RE: Error when uploading file

    Perhaps the eventdetails folder does not exist or the app doesn't have access
    to it....

    "Nathan Sokalski" wrote:
    > I am trying to write code to allow my users to upload a file. The code I am
    > using is as follows:
    >
    > Dim upfilename As String = ""
    >
    > If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength > 0
    > Then
    >
    > Dim dir As String() =
    > fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())
    >
    > upfilename = dir(dir.GetUpperBound(0))
    >
    > fileDetails.PostedFile.SaveAs(Server.MapPath("/eventdetails/") & upfilename)
    >
    > End If
    >
    >
    > When I run this code, I recieve an error similar to the following:
    >
    > Server Error in '/lvbeporgtest' Application.
    > --------------------------------------------------------------------------------
    >
    > Could not find a part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    > 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.DirectoryNotFoundException: Could not find a
    > part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    >
    > Source Error:
    >
    > An unhandled exception was generated during the execution of the
    > current web request. Information regarding the origin and location of the
    > exception can be identified using the exception stack trace below.
    >
    > Stack Trace:
    >
    > [DirectoryNotFoundException: Could not find a part of the path
    > "D:\Webdev_Site\eventdetails\resume.pdf".]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
    > FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
    > bFromProxy) +888
    > System.IO.FileStream..ctor(String path, FileMode mode) +52
    > System.Web.HttpPostedFile.SaveAs(String filename) +48
    > createevent.btnSubmit_Click(Object sender, EventArgs e) in C:\Documents
    > and Settings\Nathan
    > Sokalski\VSWebCache\[url]www.webdevlccc.com\lvbeporgtest\createevent.aspx.v b:114[/url]
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    > eventArgument) +57
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    > sourceControl, String eventArgument) +18
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    > System.Web.UI.Page.ProcessRequestMain() +1292
    >
    >
    >
    > --------------------------------------------------------------------------------
    > Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET
    > Version:1.1.4322.2300
    >
    >
    > I have used this same code before without any problems, what do I need to do
    > differently?
    >
    > --
    > Nathan Sokalski
    > [email]njsokalski@hotmail.com[/email]
    > [url]http://www.nathansokalski.com/[/url]
    >
    >
    >
    Brad Roberts Guest

  7. #6

    Default Re: Error when uploading file

    By default the ASPNET user account does not have write access to very many
    folders. Most likley it does not have write access to the folder you're
    specifying. Either grant it access or have ASP.NET run under a different
    user account by using impersonation.

    For example, you can add a line similar to this to your web.config file:
    <identity impersonate="true" userName="domain\MyAppUser">
    password="password"/>

    For testing purposes you can have it use your user account since you know
    you have the necessary permissions to write to that network location.

    Here's more info on impersonation:
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspnetimpersonation.asp[/url]

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    [url]http://SteveOrr.net[/url]


    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    news:eQe$BCnrFHA.2596@TK2MSFTNGP09.phx.gbl...
    >I am trying to write code to allow my users to upload a file. The code I am
    >using is as follows:
    >
    > Dim upfilename As String = ""
    >
    > If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength >
    > 0 Then
    >
    > Dim dir As String() =
    > fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())
    >
    > upfilename = dir(dir.GetUpperBound(0))
    >
    > fileDetails.PostedFile.SaveAs(Server.MapPath("/eventdetails/") &
    > upfilename)
    >
    > End If
    >
    >
    > When I run this code, I recieve an error similar to the following:
    >
    > Server Error in '/lvbeporgtest' Application.
    > --------------------------------------------------------------------------------
    >
    > Could not find a part of the path
    > "D:\Webdev_Site\eventdetails\resume.pdf".
    > 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.DirectoryNotFoundException: Could not find a
    > part of the path "D:\Webdev_Site\eventdetails\resume.pdf".
    >
    > Source Error:
    >
    > An unhandled exception was generated during the execution of the
    > current web request. Information regarding the origin and location of the
    > exception can be identified using the exception stack trace below.
    >
    > Stack Trace:
    >
    > [DirectoryNotFoundException: Could not find a part of the path
    > "D:\Webdev_Site\eventdetails\resume.pdf".]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +287
    > System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
    > access, FileShare share, Int32 bufferSize, Boolean useAsync, String
    > msgPath, Boolean bFromProxy) +888
    > System.IO.FileStream..ctor(String path, FileMode mode) +52
    > System.Web.HttpPostedFile.SaveAs(String filename) +48
    > createevent.btnSubmit_Click(Object sender, EventArgs e) in C:\Documents
    > and Settings\Nathan
    > Sokalski\VSWebCache\[url]www.webdevlccc.com\lvbeporgtest\createevent.aspx.v b:114[/url]
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    >
    > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
    > eventArgument) +57
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
    > sourceControl, String eventArgument) +18
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    > System.Web.UI.Page.ProcessRequestMain() +1292
    >
    >
    >
    > --------------------------------------------------------------------------------
    > Version Information: Microsoft .NET Framework Version:1.1.4322.2300;
    > ASP.NET Version:1.1.4322.2300
    >
    >
    > I have used this same code before without any problems, what do I need to
    > do differently?
    >
    > --
    > Nathan Sokalski
    > [email]njsokalski@hotmail.com[/email]
    > [url]http://www.nathansokalski.com/[/url]
    >

    Steve C. Orr [MVP, MCSD] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139