Error when uploading file

N

Nathan Sokalski

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("\".ToCharArray())

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\www.webdevlccc.com\lvbeporgtest\createevent.aspx.vb:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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?
 
C

Chris

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 said:
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("\".ToCharArray())

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\www.webdevlccc.com\lvbeporgtest\createevent.aspx.vb:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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?
 
N

Nathan Sokalski

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
(e-mail address removed)
http://www.nathansokalski.com/

Chris said:
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 said:
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("\".ToCharArray())

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\www.webdevlccc.com\lvbeporgtest\createevent.aspx.vb:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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?
 
C

Chris

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 said:
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
(e-mail address removed)
http://www.nathansokalski.com/

Chris said:
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 said:
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("\".ToCharArray())

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\www.webdevlccc.com\lvbeporgtest\createevent.aspx.vb:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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?
 
G

Guest

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

Nathan Sokalski said:
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("\".ToCharArray())

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\www.webdevlccc.com\lvbeporgtest\createevent.aspx.vb:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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?
 
S

Steve C. Orr [MVP, MCSD]

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:
http://msdn.microsoft.com/library/d...-us/cpguide/html/cpconaspnetimpersonation.asp




Nathan Sokalski said:
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("\".ToCharArray())

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\www.webdevlccc.com\lvbeporgtest\createevent.aspx.vb:114
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top