开发者

Create Folder o Save in Temp

I have Visual Studio 11 (Windows 8 Developer) i have create a downloader file:

string sUrlToReadFileFrom = "http://mysite/1.mp3";
int iLastIndex = sUrlToReadFileFrom.LastIndexOf('/');
string sDownloadFileName = sUrlToReadFileFrom.Substring(iLastIndex + 1, (sUrlToReadFileFrom.Length - iLastIndex - 1));
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("http://mysite/1.mp3"), "C:\\Windows\\Temp" + "\\" + sDownloadFileName);

But it doesn't work start! If I change the folder "C:\Windows\Temp" in "E:\Temp" the download开发者_运维知识库 start. The drive C:\ doesn't work, why? It is possible save in temp folder or you've other idea?


Not having played with Widnows 8 yet, this is only conjecture, but it's likely you don't have write permissions to that location on the C:\ as a standard privilege user.


try with this:

string tempPath = System.IO.Path.GetTempPath();

does it work?


Use the environment variable instead

Environment.GetFolderPath(Environment.LocalApplicationData)


You could use the temp folder path:

string tempPath = System.IO.Path.GetTempPath();


Use one of the following:

  • Path.GetTempPath()
  • Environment.SpecialFolder for example LocalApplicationData or MyDocuments
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜