Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.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/2/shell/5.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 - Fatal编程技术网

C# 如何将图像的路径位置从一个文件夹更改为另一个文件夹

C# 如何将图像的路径位置从一个文件夹更改为另一个文件夹,c#,asp.net,C#,Asp.net,单击add按钮后,我在path/TempFolder中有一些图片,我想将它们的位置逐个更改为path/Images,并更改它们的名称 有什么想法吗?MS有一些关于如何实现这一点的文档。您是否尝试过提出的解决方案 编辑:我已经从网站上复制了SampleMove功能,以供将来使用 // Simple synchronous file move operations with no user interface. public class SimpleFileMove { static vo

单击
add按钮后,我在
path/TempFolder
中有一些图片,我想将它们的位置逐个更改为
path/Images
,并更改它们的名称
有什么想法吗?

MS有一些关于如何实现这一点的文档。您是否尝试过提出的解决方案

编辑:我已经从网站上复制了SampleMove功能,以供将来使用

// Simple synchronous file move operations with no user interface. 
public class SimpleFileMove
{
    static void Main()
    {
        string sourceFile = @"C:\Users\Public\public\test.txt";
        string destinationFile = @"C:\Users\Public\private\test.txt";

        // To move a file or folder to a new location:
        System.IO.File.Move(sourceFile, destinationFile);

        // To move an entire directory. To programmatically modify or combine 
        // path strings, use the System.IO.Path class.
        System.IO.Directory.Move(@"C:\Users\Public\public\test\", @"C:\Users\Public\private");
    }
}

您可以使用
File.Move
()方法:


你试过什么吗?一些代码示例会很好..是的,我已经搜索过了,但他们中的大多数人都在谈论仅更改文件名我找到了此链接,但搜索“C#move file”对我不起作用!谷歌是你的朋友。听起来不错,我要找的是复制图像文件并删除以前的文件
foreach (var item in System.IO.Directory.GetFiles(@"C:\TempFolder"))
{
    string name = new System.IO.FileInfo(item).Name;
    string newName = name.Insert(name.IndexOf("."), "_new");
    System.IO.File.Move(item, System.IO.Path.Combine(@"C:\Images", newName));
}