Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Path Format not Supported

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim McGivney - 19 Oct 2005 05:33 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.