Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Every one,

Have a look at the below code:

C#
if (File.Exists(temppath))
 {
if (File.Exists(Server.MapPath("Documents") + "/" + dt.Rows[0]["ImagePath"].ToString()))
 {
   File.Delete(Server.MapPath("Documents") + "/" + dt.Rows[0]["ImagePath"].ToString());
 }
  File.Copy(temppath, Server.MapPath("Documents") + "/" + dt.Rows[0]["ImagePath"].ToString());                
 }


Here, in the following
Server.MapPath("Documents")

"Documents" is a folder name which is in my application and the files are being stored in it..
But I want to use a local folder with the same name and Instaed of above statement, I need to use the statement for local folder..
Please suggest me on this..

Regards,
Posted
Comments
Sergey Alexandrovich Kryukov 25-May-11 10:11am    
What is "storing in application", what is "in local folder"? Is it both in server-side?
--SA

1 solution

You can hardcode the physical path. i.e. D://YourFolderPath. But be sure to verify its existence before using it. As it might raise error in case when that path is unavailable.

But this is not a good approach. If it is a must for you to use, then I would recommended you to save this path in web.config or application config. So it would be easy for you to change it in future if required.

One more thing, you must have permission to add/edit/delete files from that specified folder.

Hope it helps.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 25-May-11 10:10am    
Good, I agree. (I voted 4).
More exactly, in real life there is absolute not situation where any path name could be hard-coded. In all cases it should be get from data and/or calculated based on data.
--SA
That's Aragon 26-May-11 1:17am    
Thank you for your comment and vote. Yes you are right for real life situation. Therefore I have mentioned that "this is not a good approach". I have provided recommendation for saving file path in the web.config/general settings from which one can change it easily if required in future. As it might be possible in some application where files are the major part of the application. Again thank you for your comment.

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