Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

.net file upload not working in firefox

8:08 pm on Feb 5, 2006 (gmt 0)

10+ Year Member

I'm using a simple asp.net image file upload and it works fine in IE, but I'm getting an error in firefox:

Server Error in '/' Application
Could not find a part of the path "C:\path\"

filepath = Server.MapPath("\") & "folder1\folder2\"
fileupload1.PostedFile.SaveAs(filepath & strFileName)

any thoughts why it would work fine in ie but not ff?

8:14 pm on Feb 5, 2006 (gmt 0)

10+ Year Member

8:20 pm on Feb 5, 2006 (gmt 0)

10+ Year Member

what about them?
8:40 pm on Feb 5, 2006 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

They are going the wrong way. You need forward slashes, the internet/Unix way.
8:56 pm on Feb 5, 2006 (gmt 0)

10+ Year Member

it's a windows server and it's saving a file not a url, so surely the backslashes are right?

I tried filepath = Server.MapPath("/") & "folder1/folder2/"

but that produced the same error

1:22 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

It helps if you say what the error is.
3:40 pm on Feb 6, 2006 (gmt 0)

10+ Year Member

as stated in my first post
5:53 pm on Feb 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Can you paste in the actual error message?

And file upload is server side, I'm not sure what would make it work in IE and not Firefox.

7:14 pm on Feb 6, 2006 (gmt 0)

10+ Year Member

Only thing I've changed below is my file and folder names

Server Error in '/' Application.
Could not find a part of the path "D:\websites\folders\".
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:\websites\folders\".

Source Error:

Line 133: filepath = Server.MapPath("\") & "folders\"
Line 56:
Line 135: fileupload1.PostedFile.SaveAs(filepath & strFileName)
Line 136:
Line 137: Return True

Source File: D:\websites\folders\file.aspx Line: 57

Stack Trace:

[DirectoryNotFoundException: Could not find a part of the path "D:\websites\folders\".]
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
ASP.thumbnail2_aspx.UploadMainImage() in D:\websites\folders\file.aspx:57
ASP.thumbnail2_aspx.btnUpload_Click(Object sender, EventArgs e) in D:\websites\folders\file.aspx:23
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() +1281

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

It is bizarre, but I can reproduce and have had several users confirm that it works in IE but not firefox

9:13 pm on Feb 6, 2006 (gmt 0)

10+ Year Member

Just a thought : have you tried just reading the variables without actually trying to execute the upload.. then you'd be able to see where the file is trying to go.

As the code suggests, the directory structure isn't there, so I would do an:

If Not Directory.Exists("C:\MyDir") Then
End If

I'd also strip out any \'s from the user provided filename to prevent posting to a different directory.



11:30 pm on Feb 6, 2006 (gmt 0)

10+ Year Member

emsaw thanks for the suggestion - I did that and managed to discover that

contains the full local path of the image in IE, but only the filename in Firefox. I used an if else based on the presence or not of a backslash and that allowed me to get the page to work.

Delighted to have solved the bug for users, but why would that be different in firefox?

12:51 pm on Feb 23, 2006 (gmt 0)

10+ Year Member

as someone asked me I'm posting the code I used as above here:

Dim strLongFilePath As String = fileupload1.PostedFile.FileName

Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "\")

if intFileNameLength>0 then
strFileName = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
end if

then in either case you should have strFileName containing the just the filename

2:37 am on Feb 25, 2006 (gmt 0)

10+ Year Member

You are using Server.MapPath incorrectly. This method returns the physical path of the *virtual path* passed as a parameter.

For example (C#, but same thing):

string myPath = Server.MapPath("/images/picture.jpg");

Might return "C:\inetpub\wwwroot\myapp\images\picture.jpg" depending on the physical path of the application.

When using System.IO commands, a lot of them are going to require the physical path, so utilizing the Server.MapPath() method is a convenient way of returning the desired physical path based on the the passed virtual path.


Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month