Asp.net Path正在运行,但IIS路径无法运行 [英] Asp.net Path is working but IIS path is not working

查看:85
本文介绍了Asp.net Path正在运行,但IIS路径无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

i在解决方案资源管理器下创建了一个名为subimg的文件夹(subimg不在任何文件夹下。它位于解决方案资源管理器下)。



在我的项目中,我需要为产品显示不同的图像。

所以,我需要保存并删除文件夹中的图像。



下面的代码非常适合我在localhost中运行时想要的东西。



但是在IIS服务器中托管后,它无效。



将图像保存到文件夹中

showimage.ashx.cs

***** ************


Hello,
i created one folder under solution explorer called subimg (subimg is not under any folder. it is under solution explorer).

In my project i need show different images for the product.
so,i need to save and delete images from folder .

Below code works exctaly what i want when i am running in localhost.

But after hosting in IIS Server, it is not working.

to save image into folder
showimage.ashx.cs
*****************

string path23 = context.Server.MapPath("~/subimg");
                bmpToSave1.Save("" + path23 + "/"+ ".jpg");



从文件夹中删除图像

product.aspx.cs(pageload)

************************



to delete image from folder
product.aspx.cs(pageload)
************************

try
                    {
                        var fileimgpath = Directory.GetFiles(Server.MapPath("~/subimg"));

                        foreach (string s1 in fileimgpath)
                        {
                            if (File.Exists(s1))
                            {
                                File.Delete(s1);
                            }
                        }
                    }
                    catch(Exception ex)
                    {

                    }



i试过../,只有/,没有/而不是'〜'。但不工作。



需要帮助。


i tried ../, only / , without / too instead of '~'. but not working.

help needed.

推荐答案

var fileimgpath = Directory.GetFiles(Server.MapPath("~/subimg/"));



注意: Server.MapPath中的最后一个斜杠(/)(〜 / subimg /)进入该目录并查找该目录中的所有文件非常重要。


Note: The last slash (/) in Server.MapPath("~/subimg/") is important to get into that directory and find all the files from that directory.


这篇关于Asp.net Path正在运行,但IIS路径无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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