Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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#给定路径'中的文件复制问题;不支持s格式_C#_Winforms_File Copying - Fatal编程技术网

C#给定路径'中的文件复制问题;不支持s格式

C#给定路径'中的文件复制问题;不支持s格式,c#,winforms,file-copying,C#,Winforms,File Copying,以下是我的代码,用于将文件从一个本地位置复制到另一个本地位置,并使用windows media player在winforms中播放 在文件复制期间,我收到一个异常“不支持给定路径的格式” 我似乎不明白这个问题。有人能帮忙吗?提前谢谢 Value of exepath variable- "file:\C:\Users\HP\source\repos\TestProject\TestProject\bin\Debug" Value of vdopath variable-

以下是我的代码,用于将文件从一个本地位置复制到另一个本地位置,并使用windows media player在winforms中播放

在文件复制期间,我收到一个异常“不支持给定路径的格式”

我似乎不明白这个问题。有人能帮忙吗?提前谢谢

Value of exepath variable- "file:\C:\Users\HP\source\repos\TestProject\TestProject\bin\Debug"

Value of vdopath variable- "file:\C:\Users\HP\source\repos\TestProject\TestProject\bin\Debug\Folder1\Folder2\file"

Value of strtupPath- "C:\Users\HP\source\repos\TestProject\TestProject\bin"

Value of newvdopath- "C:\Users\HP\source\repos\TestProject\TestProject\bin\vdofile.mkv"

string vdopath=Path.Combine(Application.StartupPath,“Folder1\\Folder2\\file”);字符串newvdopath=Path.Combine(Application.StartupPath,“vdofile.mkv”)。请注意,如果您的应用程序安装在
程序文件中
,则您无法在该路径中创建文件。考虑使用<代码>应用程序。代码>指令在你的课堂上。非常感谢。使用Application.StartupPath而不是exepath解决了以下问题:)
   using System.Collections.Generic;
   using System.ComponentModel;
   using System.Data;
   using System.Drawing;
   using System.Linq;
   using System.Text;
   using System.Threading.Tasks;
   using System.Windows.Forms;
   using WMPLib;
   using System.IO;

   namespace TestProject
   {
       public partial class vdo_form_tmplt1 : Form
       {
           public vdo_form_tmplt1()
           {
              InitializeComponent();
           }

           private void PlayVideo_Click(object sender, EventArgs e)
           {
            
               string exepath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

               string vdopath = System.IO.Path.Combine(exepath, "Folder1\\Folder2\\file");

               string strtupPath = System.IO.Path.GetDirectoryName(Application.StartupPath);

               string newvdopath = System.IO.Path.Combine(strtupPath, "vdofile.mkv");

               System.IO.File.Copy(vdopath, newvdopath);

               axWindowsMediaPlayer1.stretchToFit = true;
               axWindowsMediaPlayer1.URL = newvdopath;
           }

       }
   }