0

i have saved a link a database which looks like this

~\quizes\314757_499034200123763_1508831626_a.jpg

i used the following code to extract the filename

Uri uri = new Uri(BulletedList1.DataValueField.ToString());
        string filename=Path.GetFileName(uri.LocalPath);

but it gives the following error The format of the URI could not be determined.

4

3 に答える 3

0

以下を使用して作業を完了しました。

ListItem li = BulletedList1.Items[e.Index];

        string filename = Path.GetFileName(li.Value.ToString());
于 2012-08-08T08:08:39.323 に答える
0

次のようなPath.GetFileNameだけを使用できます。

var dbValue = @"~\quizes\314757_499034200123763_1508831626_a.jpg";
string filename = Path.GetFileName(dbValue);

あなたの例では、うまくいくはずです。

編集

推測にすぎませんが、データベースから BulletList コントロールに読み込まれたすべての値がある場合は、それらを読み取るためにItemsプロパティを調べることができます。おそらく次のようなものです:

 foreach (var item in BulletedList1.Items)
 {
    string filename = Path.GetFileName(item.ToString());
    // Do stuff with the file name
 }
于 2012-08-08T07:13:09.800 に答える
0

これの何が問題なのですか?

var fromDatabase = @"~\quizes\314757_499034200123763_1508831626_a.jpg";
string filename = Path.GetFileName(fromDatabase);

または、他の理由で「〜」を展開する必要がありますか? その場合、http://msdn.microsoft.com/en-us/library/system.web.virtualpathutility.aspxが役立つ場合があります。

于 2012-08-08T07:15:05.367 に答える