Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
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:
C#
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);
          }

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.
Posted
Updated 9-Nov-11 2:19am
v2

The ~ or tilda character is used by asp.net to resolve paths. It can't be used here.
 
Share this answer
 
Give the physical path. do not use relative path.
and before copy the file always check if file.exists(//path)
 
Share this answer
 
Comments
AnnSJ 9-Nov-11 8:29am    
thnx.. gave teh physical path and it worked...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900