访问根目录中的文件夹 [英] Access folders in root directory

查看:47
本文介绍了访问根目录中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个asp.net Web应用程序.我必须访问根目录下images文件夹中的图像之一.我在文件后面的代码中使用以下代码.

Hi I am developing an asp.net web application. I have to access one of the image in images folder in root directory. I am using following code in my code behind file.

string imageDirectory = HttpContext.Current.Server.MapPath("~/images/");
string imageUrl = imageDirectory + "/img1.bmp";

这在我的本地计算机上工作正常.我的问题是,当我将应用程序移至生产环境时,此代码是否有效?

This works fine in my local machine. My question is does this code work when I move my application to production ?

推荐答案

只要您的站点具有应用程序根目录/虚拟目录,它就应该存在.

It should as long as you have an application root/virtual directory for your site.

此外,您可以将这两行合并为:

Also, you can combine these two lines into:

string imageUrl = HttpContext.Current.Server.MapPath("~/images/img1.bmp");

这篇关于访问根目录中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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