C# 如何将下载的视频文件保存到项目文件夹?
我想下载视频文件并将其保存到项目文件夹中。 这是我当前的视频下载代码,并将其保存到一个文件夹中C# 如何将下载的视频文件保存到项目文件夹?,c#,asp.net,file,webclient,rest-client,C#,Asp.net,File,Webclient,Rest Client,我想下载视频文件并将其保存到项目文件夹中。 这是我当前的视频下载代码,并将其保存到一个文件夹中 string savePath = Server.MapPath("DownloadedClip/Record1.mp4"); //Delete existing file if (File.Exists(savePath)) { File.Delete(savePath); } //Create a new file using (File.C
string savePath = Server.MapPath("DownloadedClip/Record1.mp4");
//Delete existing file
if (File.Exists(savePath))
{
File.Delete(savePath);
}
//Create a new file
using (File.Create(savePath)) //Exception Occur here
{
using (WebClient wc = new WebClient())
wc.DownloadFile(url, savePath);
}
当我运行该项目时,它抛出一个异常“找不到路径的一部分”
我怎样才能解决这个问题
感谢你在这方面的帮助
谢谢。我猜您尚未创建要保存到的目录。不,我在项目文件夹中有一个名为“DownloadedClip”的目录。这假设您的工作目录是项目文件夹。可能不是。我看到一件事,执行if(File.Exists(savePath))这一行后,文件夹将被删除,并且它不会被文件添加。创建(savePath)这一行。谢谢@शेखर 这个问题已经解决了。对代码进行了如下更改:
stringfilenamecording=@“\Record1.mp4”;字符串fullpathRecording=Server.MapPath(“DownloadedClip”)+filenameRecording//如果(file.Exists(fullpathRecording)){file.Delete(fullpathRecording);}//使用(var fileRecording=file.Create(fullpathRecording)){fileRecording.Close();使用(WebClient wc=new WebClient())wc.DownloadFile(url,fullpathRecording);}创建新文件
我猜您尚未创建要保存到的目录。不,我在项目文件夹中有一个名为“DownloadedClip”的目录。这假设您的工作目录是项目文件夹。可能不是。我看到一件事,执行if(File.Exists(savePath))这一行后,文件夹将被删除,并且它不会被文件添加。创建(savePath)这一行。谢谢@शेखर 这个问题已经解决了。对代码进行了如下更改:stringfilenamecording=@“\Record1.mp4”;字符串fullpathRecording=Server.MapPath(“DownloadedClip”)+filenameRecording//如果(file.Exists(fullpathRecording)){file.Delete(fullpathRecording);}//使用(var fileRecording=file.Create(fullpathRecording)){fileRecording.Close();使用(WebClient wc=new WebClient())wc.DownloadFile(url,fullpathRecording);}