Error when uploading file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    #1

    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.Val ue <> "" AndAlso fileDetails.Pos tedFile.Content Length > 0
    Then

    Dim dir As String() =
    fileDetails.Pos tedFile.FileNam e.Split("\".ToC harArray())

    upfilename = dir(dir.GetUppe rBound(0))

    fileDetails.Pos tedFile.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\r esume.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.Direc toryNotFoundExc eption: Could not find a
    part of the path "D:\Webdev_Site \eventdetails\r esume.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:

    [DirectoryNotFou ndException: Could not find a part of the path
    "D:\Webdev_Site \eventdetails\r esume.pdf".]
    System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +287
    System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess access,
    FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean
    bFromProxy) +888
    System.IO.FileS tream..ctor(Str ing path, FileMode mode) +52
    System.Web.Http PostedFile.Save As(String filename) +48
    createevent.btn Submit_Click(Ob ject sender, EventArgs e) in C:\Documents
    and Settings\Nathan
    Sokalski\VSWebC ache\https://www.webdevlccc.com\lvbeporgt...nt.aspx.vb:114
    System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
    System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
    eventArgument) +57
    System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    sourceControl, String eventArgument) +18
    System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
    System.Web.UI.P age.ProcessRequ estMain() +1292



    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.432 2.2300; ASP.NET
    Version:1.1.432 2.2300


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

    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Chris

    #2
    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@hot mail.com> wrote in message
    news:eQe$BCnrFH A.2596@TK2MSFTN GP09.phx.gbl...[color=blue]
    >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.Val ue <> "" AndAlso fileDetails.Pos tedFile.Content Length >
    > 0 Then
    >
    > Dim dir As String() =
    > fileDetails.Pos tedFile.FileNam e.Split("\".ToC harArray())
    >
    > upfilename = dir(dir.GetUppe rBound(0))
    >
    > fileDetails.Pos tedFile.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\r esume.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.Direc toryNotFoundExc eption: Could not find a
    > part of the path "D:\Webdev_Site \eventdetails\r esume.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:
    >
    > [DirectoryNotFou ndException: Could not find a part of the path
    > "D:\Webdev_Site \eventdetails\r esume.pdf".]
    > System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +287
    > System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
    > access, FileShare share, Int32 bufferSize, Boolean useAsync, String
    > msgPath, Boolean bFromProxy) +888
    > System.IO.FileS tream..ctor(Str ing path, FileMode mode) +52
    > System.Web.Http PostedFile.Save As(String filename) +48
    > createevent.btn Submit_Click(Ob ject sender, EventArgs e) in C:\Documents
    > and Settings\Nathan
    > Sokalski\VSWebC ache\https://www.webdevlccc.com\lvbeporgt...nt.aspx.vb:114
    > System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
    >
    > System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
    > eventArgument) +57
    > System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    > sourceControl, String eventArgument) +18
    > System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
    > System.Web.UI.P age.ProcessRequ estMain() +1292
    >
    >
    >
    > --------------------------------------------------------------------------------
    > Version Information: Microsoft .NET Framework Version:1.1.432 2.2300;
    > ASP.NET Version:1.1.432 2.2300
    >
    >
    > I have used this same code before without any problems, what do I need to
    > do differently?
    >
    > --
    > Nathan Sokalski
    > njsokalski@hotm ail.com
    > http://www.nathansokalski.com/
    >[/color]


    Comment

    • Nathan Sokalski

      #3
      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
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


      "Chris" <ccalzaretta@ho tmail.com> wrote in message
      news:%23LZXConr FHA.2272@TK2MSF TNGP11.phx.gbl. ..[color=blue]
      > 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@hot mail.com> wrote in message
      > news:eQe$BCnrFH A.2596@TK2MSFTN GP09.phx.gbl...[color=green]
      >>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.Val ue <> "" AndAlso fileDetails.Pos tedFile.Content Length >
      >> 0 Then
      >>
      >> Dim dir As String() =
      >> fileDetails.Pos tedFile.FileNam e.Split("\".ToC harArray())
      >>
      >> upfilename = dir(dir.GetUppe rBound(0))
      >>
      >> fileDetails.Pos tedFile.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\r esume.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.Direc toryNotFoundExc eption: Could not find a
      >> part of the path "D:\Webdev_Site \eventdetails\r esume.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:
      >>
      >> [DirectoryNotFou ndException: Could not find a part of the path
      >> "D:\Webdev_Site \eventdetails\r esume.pdf".]
      >> System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +287
      >> System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
      >> access, FileShare share, Int32 bufferSize, Boolean useAsync, String
      >> msgPath, Boolean bFromProxy) +888
      >> System.IO.FileS tream..ctor(Str ing path, FileMode mode) +52
      >> System.Web.Http PostedFile.Save As(String filename) +48
      >> createevent.btn Submit_Click(Ob ject sender, EventArgs e) in C:\Documents
      >> and Settings\Nathan
      >> Sokalski\VSWebC ache\https://www.webdevlccc.com\lvbeporgt...nt.aspx.vb:114
      >> System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
      >>
      >> System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
      >> eventArgument) +57
      >> System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
      >> sourceControl, String eventArgument) +18
      >> System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
      >> System.Web.UI.P age.ProcessRequ estMain() +1292
      >>
      >>
      >>
      >> --------------------------------------------------------------------------------
      >> Version Information: Microsoft .NET Framework Version:1.1.432 2.2300;
      >> ASP.NET Version:1.1.432 2.2300
      >>
      >>
      >> I have used this same code before without any problems, what do I need to
      >> do differently?
      >>
      >> --
      >> Nathan Sokalski
      >> njsokalski@hotm ail.com
      >> http://www.nathansokalski.com/
      >>[/color]
      >
      >[/color]


      Comment

      • Chris

        #4
        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@hot mail.com> wrote in message
        news:OS6fa3orFH A.1252@TK2MSFTN GP09.phx.gbl...[color=blue]
        > 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
        > njsokalski@hotm ail.com
        > http://www.nathansokalski.com/
        >
        > "Chris" <ccalzaretta@ho tmail.com> wrote in message
        > news:%23LZXConr FHA.2272@TK2MSF TNGP11.phx.gbl. ..[color=green]
        >> 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@hot mail.com> wrote in message
        >> news:eQe$BCnrFH A.2596@TK2MSFTN GP09.phx.gbl...[color=darkred]
        >>>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.Val ue <> "" AndAlso fileDetails.Pos tedFile.Content Length
        >>> > 0 Then
        >>>
        >>> Dim dir As String() =
        >>> fileDetails.Pos tedFile.FileNam e.Split("\".ToC harArray())
        >>>
        >>> upfilename = dir(dir.GetUppe rBound(0))
        >>>
        >>> fileDetails.Pos tedFile.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\r esume.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.Direc toryNotFoundExc eption: Could not find
        >>> a part of the path "D:\Webdev_Site \eventdetails\r esume.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:
        >>>
        >>> [DirectoryNotFou ndException: Could not find a part of the path
        >>> "D:\Webdev_Site \eventdetails\r esume.pdf".]
        >>> System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +287
        >>> System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
        >>> access, FileShare share, Int32 bufferSize, Boolean useAsync, String
        >>> msgPath, Boolean bFromProxy) +888
        >>> System.IO.FileS tream..ctor(Str ing path, FileMode mode) +52
        >>> System.Web.Http PostedFile.Save As(String filename) +48
        >>> createevent.btn Submit_Click(Ob ject sender, EventArgs e) in
        >>> C:\Documents and Settings\Nathan
        >>> Sokalski\VSWebC ache\https://www.webdevlccc.com\lvbeporgt...nt.aspx.vb:114
        >>> System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
        >>>
        >>> System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
        >>> eventArgument) +57
        >>> System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
        >>> sourceControl, String eventArgument) +18
        >>> System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
        >>> +33
        >>> System.Web.UI.P age.ProcessRequ estMain() +1292
        >>>
        >>>
        >>>
        >>> --------------------------------------------------------------------------------
        >>> Version Information: Microsoft .NET Framework Version:1.1.432 2.2300;
        >>> ASP.NET Version:1.1.432 2.2300
        >>>
        >>>
        >>> I have used this same code before without any problems, what do I need
        >>> to do differently?
        >>>
        >>> --
        >>> Nathan Sokalski
        >>> njsokalski@hotm ail.com
        >>> http://www.nathansokalski.com/
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Steve C. Orr [MVP, MCSD]

          #5
          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="tr ue" userName="domai n\MyAppUser">
          password="passw ord"/>

          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:
          http://msdn.microsoft.com/library/de...ersonation.asp

          --
          I hope this helps,
          Steve C. Orr, MCSD, MVP



          "Nathan Sokalski" <njsokalski@hot mail.com> wrote in message
          news:eQe$BCnrFH A.2596@TK2MSFTN GP09.phx.gbl...[color=blue]
          >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.Val ue <> "" AndAlso fileDetails.Pos tedFile.Content Length >
          > 0 Then
          >
          > Dim dir As String() =
          > fileDetails.Pos tedFile.FileNam e.Split("\".ToC harArray())
          >
          > upfilename = dir(dir.GetUppe rBound(0))
          >
          > fileDetails.Pos tedFile.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\r esume.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.Direc toryNotFoundExc eption: Could not find a
          > part of the path "D:\Webdev_Site \eventdetails\r esume.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:
          >
          > [DirectoryNotFou ndException: Could not find a part of the path
          > "D:\Webdev_Site \eventdetails\r esume.pdf".]
          > System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +287
          > System.IO.FileS tream..ctor(Str ing path, FileMode mode, FileAccess
          > access, FileShare share, Int32 bufferSize, Boolean useAsync, String
          > msgPath, Boolean bFromProxy) +888
          > System.IO.FileS tream..ctor(Str ing path, FileMode mode) +52
          > System.Web.Http PostedFile.Save As(String filename) +48
          > createevent.btn Submit_Click(Ob ject sender, EventArgs e) in C:\Documents
          > and Settings\Nathan
          > Sokalski\VSWebC ache\https://www.webdevlccc.com\lvbeporgt...nt.aspx.vb:114
          > System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
          >
          > System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
          > eventArgument) +57
          > System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
          > sourceControl, String eventArgument) +18
          > System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
          > System.Web.UI.P age.ProcessRequ estMain() +1292
          >
          >
          >
          > --------------------------------------------------------------------------------
          > Version Information: Microsoft .NET Framework Version:1.1.432 2.2300;
          > ASP.NET Version:1.1.432 2.2300
          >
          >
          > I have used this same code before without any problems, what do I need to
          > do differently?
          >
          > --
          > Nathan Sokalski
          > njsokalski@hotm ail.com
          > http://www.nathansokalski.com/
          >[/color]


          Comment

          Working...