2009-09-30 45 views
0

我需要從這個網址得到的只是文件名:XSL獲取文件名從URL

http://feedproxy.google.com/~r/TEDTalks_video/~5/XT8k_DqlzGc/KarenArmstrong_2009G.mp4 

所以我需要得到:

KarenArmstrong_2009G 

我需要的文件名,所以我可以添加到.JPG它和另一個基地網址。

+0

你可以使用JavaScript來獲取你的文件名? - 例如http://stackoverflow.com/questions/511761/js-function-to-get-filename-from-url – Scozzard 2009-09-30 20:40:15

+3

重複? http://stackoverflow.com/questions/1500067/xsl-mediacontent – 2009-10-01 06:59:29

回答

0

嗨,你可以使用此代碼

private void button1_Click(object sender, EventArgs e) 
    { 
     System.Uri uri = new System.Uri(@"http://feedproxy.google.com/~r/TEDTalks_video/~5/XT8k_DqlzGc/KarenArmstrong_2009G.mp4"); 
     string filename = ""; 

     filename = System.IO.Path.GetFileName(uri.LocalPath); /// filename="KarenArmstrong_2009G.mp4" 
     filename = filename.Substring(0, filename.Length - 4);/// filename="KarenArmstrong_2009G" 
     MessageBox.Show(filename); 
    }