what about them?
They are going the wrong way. You need forward slashes, the internet/Unix way.
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
It helps if you say what the error is.
as stated in my first post
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.
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\".
Line 133: filepath = Server.MapPath("\") & "folders\"
Line 135: fileupload1.PostedFile.SaveAs(filepath & strFileName)
Line 137: Return True
Source File: D:\websites\folders\file.aspx Line: 57
[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
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
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
I'd also strip out any \'s from the user provided filename to prevent posting to a different directory.
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?
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)
then in either case you should have strFileName containing the just the filename
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.