Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将下载的视频文件保存到项目文件夹?_C#_Asp.net_File_Webclient_Rest Client - Fatal编程技术网

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);}