In an aspx page I run the following C# code-behind:
string filename = null;
filename = txtUpload.PostedFile.FileName.Trim();
//save the file
txtUpload.PostedFile.SaveAs(@"C:\home\sites\bobo.com\web\" + filename);
I get the following error: The given path's format is not supported.
Any suggestions as to the proper format for the path would be appreciated.
Thanks,
Jim
Peter Rilling - 19 Oct 2005 06:41 GMT
Check the variable "filename". Name sure it contains what you expect and
nothing more. Also, see what happens if you remove the ".com" from the
path.
> In an aspx page I run the following C# code-behind:
> string filename = null;
[quoted text clipped - 8 lines]
> Thanks,
> Jim
Shaunak P - 19 Oct 2005 07:15 GMT
Hi Jim,
Looking at your code here my 5 cents :
your code : filename = txtUpload.PostedFile.FileName.Trim(); will return
the full filename
e.g c:\test\fileUploads\filetoupload.txt
hence file name = c:\test\fileUploads\filetoupload.txt
now when you do
txtUpload.PostedFile.SaveAs(@"C:\home\sites\bobo.com\web\" + filename)
you are doing (@"C:\home\sites\bobo.com\web\" +
"c:\test\fileUploads\filetoupload.txt")
hence it will try to save the file in the path :
C:\home\sites\bobo.com\web\c:\test\fileUploads\filetoupload.txt
which is invalid format coz of c:\ being twice and hence you getting the
invalid format error
********************************
Hope this helps,
S.H.A.U.N ™ (M.C.P)
Shounak P
http://blogs.wwwcoder.com/shaunakp
*********************************
> In an aspx page I run the following C# code-behind:
> string filename = null;
[quoted text clipped - 8 lines]
> Thanks,
> Jim
Jouni Karppinen - 19 Oct 2005 11:15 GMT
When working with file names and paths it's recommended to use
System.IO.Path-class
For example:
string fName = System.IO.Path.GetFileName(filename) //gets only the file
name from full path
It's also recommended to use System.IO.Path.Combine() method to build paths.
So I would do it like:
txtUpload.PostedFile.SaveAs(Path.Combine(@"C:\home\sites\bobo.com\web",
Path.GetFileName(filename));
> Hi Jim,
>
[quoted text clipped - 35 lines]
> > Thanks,
> > Jim
altunbay - 19 Oct 2005 10:46 GMT
Yuo should double the backslashes
ex: c:\\inetpub\\.....
> In an aspx page I run the following C# code-behind:
> string filename = null;
[quoted text clipped - 8 lines]
> Thanks,
> Jim
Juan T. Llibre - 19 Oct 2005 11:27 GMT
re:
> Yuo should double the backslashes
> ex: c:\\inetpub\\.....
Actually, no, because he's using the literal @ :
SaveAs(@"C:\home\sites\bobo.com\web\"
The @ means that he does *not* have to double the backslashes.
The correct answer was posted by Shaunak.
The code concatenates two full file paths,
and that is not acceptable as a path format.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
> Yuo should double the backslashes
> ex: c:\\inetpub\\.....
[quoted text clipped - 11 lines]
>> Thanks,
>> Jim