C# 将照片列表复制到其他文件夹

C# 将照片列表复制到其他文件夹,c#,image,copy,nullreferenceexception,C#,Image,Copy,Nullreferenceexception,我有一个列表框,列表框项目中有照片列表我有照片目录如何将这些照片复制到所选目录 int numberoflistbox = listBox2.Items.Count; string[] number = new string[numberoflistbox]; for (i = 0; i <= listBox2.Items.Count; i++) { number[i] = listBox2.Items[i].ToString(); foreach (string f in

我有一个列表框,列表框项目中有照片列表我有照片目录如何将这些照片复制到所选目录

int numberoflistbox = listBox2.Items.Count;
string[] number = new string[numberoflistbox];
for (i = 0; i <= listBox2.Items.Count; i++)
{
    number[i] = listBox2.Items[i].ToString();
    foreach (string f in number)
    {
        string a = toolStripTextBox2.Text;
        string b = toolStripTextBox1.Text;
        string fName = f.Substring(a.Length + 1);

        File.Copy(Path.Combine(a, fName), Path.Combine(a, fName), true);
    }
}
错误:

对象引用未设置为对象的实例


对于此行:字符串fName=f.Substringa.Length+1

使用FileStream以编程方式将图片分配给控件,以便主映像保持未打开状态

var fs = new FileStream("Image Address",FileMode.Open);
Image img = Image.FromStream(fs);
picturebox.Image=img;
fs.Close();
fs.Dispose();

如果不起作用,那是失败还是什么都不做?错误消息?请解释您遇到的问题。您是否收到异常/错误?代码正在运行,但没有复制照片吗?它向我显示了以下错误:进程无法访问文件“C:\Users\Ja\Desktop\10287328_301885279970384_684647408_n.jpg”,因为它正在被另一个进程使用。如果您显然没有在另一个应用程序中打开任何照片,如果您注销并重新登录到Windows,会发生什么情况?请关闭正在查看照片的程序!!
var fs = new FileStream("Image Address",FileMode.Open);
Image img = Image.FromStream(fs);
picturebox.Image=img;
fs.Close();
fs.Dispose();