473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Elegant way to get name of uploaded file?

Hello,

When it's needed to upload a file, and get the name of it:

uploadfile is a HtmlInputFile type:

string NameOfFile = uploadfile.PostedFile.FileName;

NameOfFile will not only get the name of the file, but the complete path on
which it was on the client ("C:\somefolder\test.exe"). How to get just the
file name (test.exe), without path information?

I know, I could just cut the string, search for the appearance of "/" or "\"
cut the rest etc. but, isn't there a more elegant way?
Nov 19 '05 #1
6 1199
The path class:
http://msdn.microsoft.com/library/de...classtopic.asp
provides serveral helpful function such as Path.GetFileName (which will get
you the filename that you wanted)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"the friendly display name" wrote:
Hello,

When it's needed to upload a file, and get the name of it:

uploadfile is a HtmlInputFile type:

string NameOfFile = uploadfile.PostedFile.FileName;

NameOfFile will not only get the name of the file, but the complete path on
which it was on the client ("C:\somefolder\test.exe"). How to get just the
file name (test.exe), without path information?

I know, I could just cut the string, search for the appearance of "/" or "\"
cut the rest etc. but, isn't there a more elegant way?

Nov 19 '05 #2
System.IO.Path.GetFileName()

"the friendly display name"
<th********************@discussions.microsoft.co m> wrote in message
news:B2**********************************@microsof t.com...
Hello,

When it's needed to upload a file, and get the name of it:

uploadfile is a HtmlInputFile type:

string NameOfFile = uploadfile.PostedFile.FileName;

NameOfFile will not only get the name of the file, but the complete path on
which it was on the client ("C:\somefolder\test.exe"). How to get just the
file name (test.exe), without path information?

I know, I could just cut the string, search for the appearance of "/" or "\"
cut the rest etc. but, isn't there a more elegant way?
Nov 19 '05 #3
This brings up an interesting issue. What is the path when other platforms
such as Mac or Unix upload a file to the server? Each platform has their
own way of representing paths and will the Path class be able to take this
into account?

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:45**********************************@microsof t.com...
The path class:
http://msdn.microsoft.com/library/de...classtopic.asp
provides serveral helpful function such as Path.GetFileName (which will
get
you the filename that you wanted)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"the friendly display name" wrote:
Hello,

When it's needed to upload a file, and get the name of it:

uploadfile is a HtmlInputFile type:

string NameOfFile = uploadfile.PostedFile.FileName;

NameOfFile will not only get the name of the file, but the complete path
on
which it was on the client ("C:\somefolder\test.exe"). How to get just
the
file name (test.exe), without path information?

I know, I could just cut the string, search for the appearance of "/" or
"\"
cut the rest etc. but, isn't there a more elegant way?

Nov 19 '05 #4
Hi Peter,

The MSDN documentation lists only Windows products under the "Platforms" for
this class. So I do not really know how it will work when receiving files
from the Unix or Mac. I have not tried it myself.

If any one has Unix or Mac, wants to try it and let us know the result, then
they can try this page from my website:
http://www.webswapp.com/demos/PathClass.aspx which will display back the
outcome; whether the Path method catches an exception or manages to get the
filenames correctly.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Peter Rilling" wrote:
This brings up an interesting issue. What is the path when other platforms
such as Mac or Unix upload a file to the server? Each platform has their
own way of representing paths and will the Path class be able to take this
into account?

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:45**********************************@microsof t.com...
The path class:
http://msdn.microsoft.com/library/de...classtopic.asp
provides serveral helpful function such as Path.GetFileName (which will
get
you the filename that you wanted)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"the friendly display name" wrote:
Hello,

When it's needed to upload a file, and get the name of it:

uploadfile is a HtmlInputFile type:

string NameOfFile = uploadfile.PostedFile.FileName;

NameOfFile will not only get the name of the file, but the complete path
on
which it was on the client ("C:\somefolder\test.exe"). How to get just
the
file name (test.exe), without path information?

I know, I could just cut the string, search for the appearance of "/" or
"\"
cut the rest etc. but, isn't there a more elegant way?


Nov 19 '05 #5
Tried it from Linux, it works.

Btw. the description from the MSDN page says it already, that it is
cross-plattform:

"Performs operations on String instances that contain file or directory path
information. These operations are performed in a cross-platform manner."

"Phillip Williams" wrote:
Hi Peter,

The MSDN documentation lists only Windows products under the "Platforms" for
this class. So I do not really know how it will work when receiving files
from the Unix or Mac. I have not tried it myself.

If any one has Unix or Mac, wants to try it and let us know the result, then
they can try this page from my website:
http://www.webswapp.com/demos/PathClass.aspx which will display back the
outcome; whether the Path method catches an exception or manages to get the
filenames correctly.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Peter Rilling" wrote:
This brings up an interesting issue. What is the path when other platforms
such as Mac or Unix upload a file to the server? Each platform has their
own way of representing paths and will the Path class be able to take this
into account?

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:45**********************************@microsof t.com...
The path class:
http://msdn.microsoft.com/library/de...classtopic.asp
provides serveral helpful function such as Path.GetFileName (which will
get
you the filename that you wanted)
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"the friendly display name" wrote:

> Hello,
>
> When it's needed to upload a file, and get the name of it:
>
> uploadfile is a HtmlInputFile type:
>
> string NameOfFile = uploadfile.PostedFile.FileName;
>
> NameOfFile will not only get the name of the file, but the complete path
> on
> which it was on the client ("C:\somefolder\test.exe"). How to get just
> the
> file name (test.exe), without path information?
>
> I know, I could just cut the string, search for the appearance of "/" or
> "\"
> cut the rest etc. but, isn't there a more elegant way?


Nov 19 '05 #6
Didn't mean that the Path class would be invoked on a Mac computer, but if
you are running a website on Windows, and a Mac client (using something like
the Safari browser) visits your webpage and uploads a file using the file
upload tag, then the path received by the server would probably be the path
would probably be Mac formatted.

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:5E**********************************@microsof t.com...
Hi Peter,

The MSDN documentation lists only Windows products under the "Platforms"
for
this class. So I do not really know how it will work when receiving files
from the Unix or Mac. I have not tried it myself.

If any one has Unix or Mac, wants to try it and let us know the result,
then
they can try this page from my website:
http://www.webswapp.com/demos/PathClass.aspx which will display back the
outcome; whether the Path method catches an exception or manages to get
the
filenames correctly.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Peter Rilling" wrote:
This brings up an interesting issue. What is the path when other
platforms
such as Mac or Unix upload a file to the server? Each platform has their
own way of representing paths and will the Path class be able to take
this
into account?

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:45**********************************@microsof t.com...
> The path class:
> http://msdn.microsoft.com/library/de...classtopic.asp
> provides serveral helpful function such as Path.GetFileName (which will
> get
> you the filename that you wanted)
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "the friendly display name" wrote:
>
>> Hello,
>>
>> When it's needed to upload a file, and get the name of it:
>>
>> uploadfile is a HtmlInputFile type:
>>
>> string NameOfFile = uploadfile.PostedFile.FileName;
>>
>> NameOfFile will not only get the name of the file, but the complete
>> path
>> on
>> which it was on the client ("C:\somefolder\test.exe"). How to get just
>> the
>> file name (test.exe), without path information?
>>
>> I know, I could just cut the string, search for the appearance of "/"
>> or
>> "\"
>> cut the rest etc. but, isn't there a more elegant way?


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john | last post by:
Hi Here's what I want: After uploading the file, I would like to preview the filename and the original path uploaded from the client side and not what is now uploaded to the server.. for...
8
by: Braky Wacky | last post by:
Hello, I have an ASP.NET webpage that uses an instance of System.Web.UI.HtmlControls.HtmlInputFile for uploading files to our server. I came across the documentation at MSDN for upping the...
0
by: Jameel | last post by:
I am facing 2 problems: 1. I have files uploaded to the server and have the relevant information in database, and now I want to pull the image name and path from database and have the images...
4
by: riteshjain82 | last post by:
Hi, Please go through this: I am having a file (default.asp) on which i am taking many details from a user before mailing it to someone. I have also provided the user with a facility of...
6
by: sathyashrayan | last post by:
Dear Group, Please look at the following demo link. http://www.itsravi.com/demo/new_pms/admin/addproject.php
14
by: suryadithya | last post by:
Hi, I am very new to php. And I have got to submit a project very soon (By tomorrow evening). So please help. The problem is this. I have created a file upload mechanism where the uploaded files...
2
by: Muddasir | last post by:
Hi All. Anyone plz tell me how can I upload a file with the file name of my choice. am having problem with this, the file got uploaded but not with the name I wanted to...how can I do this...
0
by: Tony M | last post by:
vs 2005 - vb - web page - xp pro I'm trying to use the fileupload control. I assume I need to add a user name and password, but can't figure out how. Dim UpLoadPath As String UpLoadPath =...
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.