[英]Saving File on Desktop by c#
我正在使用一個向我返回一些數據的Web服務。 我正在將該數據寫入文本文件。 我的問題是我已經在c#代碼中指定了一個文件,我想在其中打開一個對話框,要求用戶將文件保存在所需的位置。 我在這里發布我使用過的代碼。 請幫助我修改我的代碼。 實際上,從Internet搜索之后,所有人都有不同的看法,並且由於我不想在一定程度上更改代碼,因此需要對代碼進行很多更改。 我可以在測試文件中寫入內容,但是如何要求用戶在計算機上輸入所需的位置?
StreamWriter file = new StreamWriter("D:\\test.txt");
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(yahooURL);
// Get the response from the Internet resource.
HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
// Read the body of the response from the server.
StreamReader strm =
new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);
string content = "";
for (int i = 0; i < symbols.Length; i++)
{
// Loop through each line from the stream,
// building the return XML Document string
if (symbols[i].Trim() == "")
continue;
content = strm.ReadLine().Replace("\"", "");
string[] contents = content.ToString().Split(',');
foreach (string dataToWrite in contents)
{
file.WriteLine(dataToWrite);
}
}
file.Close();
嘗試這個
using (WebClient Client = new WebClient ())
{
Client.DownloadFile("http://www.abc.com/file/song/a.mpeg", "a.mpeg");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.