[英]Save an image to outside the directory in asp.net
I am trying to save an image to server.Server directory structure is as follows 我正在尝试将图像保存到服务器。服务器目录结构如下
httpdocs-
Folder-
Page.aspx
and 和
httpdocs-
Images-
Subimages
The Folder and Images are under the httpdocs. 文件夹和图像位于httpdocs下。 I need to save the image to subimages folder from pages.aspx.
我需要将图像从pages.aspx保存到subimages文件夹。 Saving image code is on pages.aspx.
保存图像代码在pages.aspx上。
I tried string CroppedImagePath = Server.MapPath("~/Images/Subimages"+file)
But not get the exact result 我试过了
string CroppedImagePath = Server.MapPath("~/Images/Subimages"+file)
但没有得到确切的结果
Unless file
contains a leading /
character, that's going to end up saving as something like: 除非
file
包含前导/
字符,否则最终将其另存为:
~/Images/Subimagesfilename.ext
Use Path.Combine()
to build a path name. 使用
Path.Combine()
构建路径名。 Something like this: 像这样:
var CroppedImagePath = Path.Combine(Server.MapPath("~/Images/Subimages"), file);
试试这个字符串CroppedImagePath = Server.MapPath(“〜/ Images / Subimages /” + file)/在Subimages之后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.