将文件存储在本地文件夹中,而不是将其存储在应用程序中. [英] storing a file in local folder instead of storing it in an application.

查看:121
本文介绍了将文件存储在本地文件夹中,而不是将其存储在应用程序中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

看看下面的代码:

Hi Every one,

Have a look at the below code:

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")


文档"是我的应用程序中的文件夹名称,文件正在其中存储..
但是我想使用与上述语句具有相同名称和Instaed的本地文件夹,我需要对本地文件夹使用该语句..
请给我建议..

问候,


"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,

推荐答案

您可以对物理路径进行硬编码.即D://YourFolderPath.但是请务必在使用前验证其存在.如果在该路径不可用的情况下可能会引发错误.

但这不是一个好方法.如果必须使用它,那么我建议您将此路径保存在web.config或应用程序配置中.因此,如果需要,将来可以很容易地对其进行更改.

还有一件事,您必须具有从该指定文件夹添加/编辑/删除文件的权限.

希望对您有所帮助.
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.


这篇关于将文件存储在本地文件夹中,而不是将其存储在应用程序中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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