Forum Moderators: open
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?
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 TrueSource 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() +1281Version 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
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
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?
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
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.