473,508 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract filename from url

Hello!

Could someone please provide me a sample, how to extract filename from url?

http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

Nov 18 '05 #1
9 15506
Hi,

use the Scheme property of the Uri object. It will give you the scheme
(file, news etc.) for the Uri object.

Regards
Joyjit

"Scott Reynolds" <ad***@it-xenius.co.uk> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hello!

Could someone please provide me a sample, how to extract filename from url?
http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

Nov 18 '05 #2

You can use System.Url class to get each parts of url. but u can not get the
filename alone.

Uri u = new
Uri("http://www.mydomain.com/eng/Default.aspx");
u.LocalPath

string s = "http://www.mydomain.com/eng/Default.aspx";
string fileName= s.Substring(s.LastIndexOf("/") +
1));
You one of substring method to find out the filename alone.

Regards,
Govind.
"Scott Reynolds" wrote:
Hello!

Could someone please provide me a sample, how to extract filename from url?

http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

Nov 18 '05 #3

string s = "http://www.mydomain.com/eng/Default.aspx";

string fileName = s.SubString(s.LastIndex(@'/')+1);

hope this helps
-----Original Message-----
Hello!

Could someone please provide me a sample, how to extract filename from url?
http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

.

Nov 18 '05 #4
Scott Reynolds <ad***@it-xenius.co.uk> typed:
Hello!

Could someone please provide me a sample, how to extract filename
from url?

http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott


You can do it in different ways. A easy way could be this:

Uri uri = Request.Url;

string[] segment = uri.Segments;

int position = segment.Length - 1;

string page = segment[position];

Response.Write(page);
--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #5
Thank you all!
Nov 18 '05 #6
Hi Scott,

You can get the pagename using this code.
string strPageName = System.IO.Path.GetFileName(Request.Path);

or

string strPageName =
System.IO.Path.GetFileName("http://www.mydomain.com/eng/Default.aspx");

Thanks

Raghavendra

"Scott Reynolds" <ad***@it-xenius.co.uk> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hello!

Could someone please provide me a sample, how to extract filename from url?
http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

Nov 18 '05 #7
try:

string URL = "http://www.mydomain.com/eng/Default.aspx";
int afterLastSlashIndex = URL.lastIndexOf('/') + 1;
string filename = URL.substring(afterLastSlashIndex , ULR.length -
afterLastSlashIndex);

/mortb

"Scott Reynolds" <ad***@it-xenius.co.uk> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hello!

Could someone please provide me a sample, how to extract filename from url?
http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

Nov 18 '05 #8


Mystr="http://www.mydomain.com/eng/Default.aspx"
Dim filename As String()
filename = mystr.Split("\")
response.write(filename(filename.Length - 1))
Hope this would help
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #9
TJS
Dim Mystr As String ="http://www.mydomain.com/eng/Default.aspx"
Dim filename As String()
filename = mystr.Split("/")
response.write( filename (uBound(filename)) )
"Scott Reynolds" <ad***@it-xenius.co.uk> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Hello!

Could someone please provide me a sample, how to extract filename from url?
http://www.mydomain.com/eng/Default.aspx -> Default.aspx

Thanks

Scott

Nov 18 '05 #10

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

Similar topics

5
12462
by: Paul | last post by:
Hi, Using the code below I can extract the filename from a path but I would like to know how to get just the path too. So if the full path is "C:\A Long Time Ago\In A Galaxy\Far Far...
3
3185
by: PeterB | last post by:
Hello! I'm using the following method to retrieve the filname from a full server path: <% sub getfname(strPath) Dim fName fName = Mid(strPath,InStrRev(strPath,"\")+1) 'fName = strPath
1
1374
by: Joe | last post by:
Hi, I have a filename abcxyz.doc. Can someone tell me how do I extract the file extension .doc from the filename in ASP.NET using VB. For your reference a user is typing a filename in the...
3
30759
by: Adam Faulkner via DotNetMonster.com | last post by:
I want to create a method within a class that opens a Microsoft Word 2000 Document and has the facility to Create a new word document and then extract a Page that exists within the original Word...
8
2817
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
14
3001
by: skyy | last post by:
hi... i got this filename test.txt with the location of c:\testfolder\test.txt i can get the full path name from the upload object. But i want to extract only the filename.(test.txt) i tried...
3
2634
by: adimangla | last post by:
Hi :-) I am creating a software that will save the present state of all the applications running on the desktop (WinXP). Can anyone point out the method to extract the filenames from the...
5
5733
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to...
0
1363
by: rajib123 | last post by:
I am trying to write a windows utility that downloads some files from an ftp site to a local directory and then uploads those files to another ftp site. The files that I need to download are posted...
0
7226
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
7125
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...
1
7049
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...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.