homepage Welcome to WebmasterWorld Guest from 54.196.62.23
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
.net file upload not working in firefox
musicales

10+ Year Member



 
Msg#: 3230 posted 8:08 pm on Feb 5, 2006 (gmt 0)

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?

 

Longhaired Genius

10+ Year Member



 
Msg#: 3230 posted 8:14 pm on Feb 5, 2006 (gmt 0)

Backslashes!

musicales

10+ Year Member



 
Msg#: 3230 posted 8:20 pm on Feb 5, 2006 (gmt 0)

what about them?

drhowarddrfine

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3230 posted 8:40 pm on Feb 5, 2006 (gmt 0)

They are going the wrong way. You need forward slashes, the internet/Unix way.

musicales

10+ Year Member



 
Msg#: 3230 posted 8:56 pm on Feb 5, 2006 (gmt 0)

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

mrMister

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3230 posted 1:22 pm on Feb 6, 2006 (gmt 0)

It helps if you say what the error is.

musicales

10+ Year Member



 
Msg#: 3230 posted 3:40 pm on Feb 6, 2006 (gmt 0)

as stated in my first post

carguy84

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3230 posted 5:53 pm on Feb 6, 2006 (gmt 0)

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.

musicales

10+ Year Member



 
Msg#: 3230 posted 7:14 pm on Feb 6, 2006 (gmt 0)

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

emsaw

5+ Year Member



 
Msg#: 3230 posted 9:13 pm on Feb 6, 2006 (gmt 0)

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
Directory.CreateDirectory("C:\MyDir")
End If

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

HTH,

Mark

musicales

10+ Year Member



 
Msg#: 3230 posted 11:30 pm on Feb 6, 2006 (gmt 0)

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

fileupload.PostedFile.FileName 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?

musicales

10+ Year Member



 
Msg#: 3230 posted 12:51 pm on Feb 23, 2006 (gmt 0)

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)
else
strFileName=strLongFilePath
end if

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

sharbel

10+ Year Member



 
Msg#: 3230 posted 2:37 am on Feb 25, 2006 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved