将图像文件从一个文件夹复制到另一个文件夹 [英] copying image files from one folder to another

查看:96
本文介绍了将图像文件从一个文件夹复制到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


想知道是否有人可以指导我.
我正在尝试将图像文件从一个位置复制到另一位置.
原始文件的路径作为值存储在gridview的单元格中.

到目前为止,我尝试过的代码如下:


wonder if someone can please guide me on this.
i m trying to copy image files from one location to another.
the path of the original file is stored as a value in a cell in a gridview.

so far the code i have tried is like so:

for (i = 0; i <= GridView1.Rows.Count-1 ; i++)
           {

               string filepath = GridView1.Rows[i].Cells[2].Text;
               string filename = GridView1.Rows[i].Cells[3].Text; 
           System.IO.File.Copy(filepath, "~/" + foldername + "/" + filename);
          }


调试时,文件路径中的值为〜/carpics/back.bmp",文件名中的值为"back.bmp"
file.copy处,给我一个错误找不到路径〜/carpics/back.bmp"的一部分."

请帮助我解决此问题,或者如果还有其他方法可以复制图像文件.
请指导.


on debugging the value in filepath is "~/carpics/back.bmp" and The value in filename is "back.bmp"
At the file.copy it gives me an error "Could not find a part of the path ''~/carpics/back.bmp''."

Please help me fix this or if there is another way to copy image files.
please guide.
thanks.

推荐答案

asp.net使用〜或tilda字符来解析路径.不能在这里使用.
The ~ or tilda character is used by asp.net to resolve paths. It can''t be used here.


给出物理路径.不要使用相对路径.
在复制文件之前,请务必先检查if file.exists(//path)
Give the physical path. do not use relative path.
and before copy the file always check if file.exists(//path)


这篇关于将图像文件从一个文件夹复制到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆