在我的.NET网站使用Directory.GetFiles [英] Using Directory.GetFiles in my .net website

查看:234
本文介绍了在我的.NET网站使用Directory.GetFiles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我建我的。NET的网站,我使用检索文件的路径 Directory.GetFiles(@D:\项目\图像);

但是,当我部署它的互联网服务器上,我必须要改变这个文件夹的链接,你能不能帮我,我怎么能做到这一点?我可以使用相对链接Directory.GetFiles()或如何?

解决方案

在web.config中碰到这样的:

 <结构>
    <的appSettings>
        <添加键=ImagesFolder值=\图像/>
    < /的appSettings>
< /结构>
 

然后在ASP.NET C#code的后面,则可以使用:

  VAR ImagesFolder = ConfigurationManager.AppSettings [ImagesFolder];

var中的文件= Directory.GetFiles(使用Server.Mappath(ImagesFolder));
 

记住,你需要添加一个引用 System.Configuration 组件,否则您将无法添加using语句,并访问 ConfigurationManager中

在这种方式有没有硬codeD值,您可以通过编辑Web服务器上的部署文件夹中的web.config文件中写上你想要的appsetting值。<​​/ P>

When I built my .net site, I retrieved files paths using Directory.GetFiles(@"D:\project\images");

But when I deployed it on internet server, I have to change the link of this folder, can you help me how can I do that?? can I use relative link in Directory.GetFiles() or how??

解决方案

in the web.config have something like:

<configuration>
    <appSettings>
        <add key="ImagesFolder" value="\Images" />
    </appSettings>
</configuration>

then in your ASP.NET C# code behind you can use:

var ImagesFolder = ConfigurationManager.AppSettings["ImagesFolder"];

var files = Directory.GetFiles(Server.MapPath(ImagesFolder));

mind that you need to add a reference to the System.Configuration assembly or you won't be able to add the using statement and access the ConfigurationManager.

in this way there are no hard coded values and you can write the value you want for that appsetting by editing the web.config file in the deployed folder on the web server.

这篇关于在我的.NET网站使用Directory.GetFiles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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