By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,155 Members | 952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,155 IT Pros & Developers. It's quick & easy.

Path Format not Supported

P: n/a
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.c om\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

Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

"Jim McGivney" <mc****@no-spam.sbcglobal.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.c om\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

Nov 19 '05 #2

P: n/a
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.c om\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\fil etoupload.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
*********************************

"Jim McGivney" wrote:
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.c om\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

Nov 19 '05 #3

P: n/a
Yuo should double the backslashes
ex: c:\\inetpub\\.....

"Jim McGivney" wrote:
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.c om\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

Nov 19 '05 #4

P: n/a
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));


"Shaunak P" wrote:
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.c om\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\fil etoupload.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
*********************************

"Jim McGivney" wrote:
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.c om\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

Nov 19 '05 #5

P: n/a
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 Espaol : http://asp.net.do/foros/
======================================
"altunbay" <al******@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com... Yuo should double the backslashes
ex: c:\\inetpub\\.....

"Jim McGivney" wrote:
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.c om\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

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.