导航
  • 主页
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

图像保存时遇到问题!

quou2002 2004-08-03 08:17:37
System.Drawing.Image img=System.Drawing.Image.FromFile(Server.MapPath("test.gif"));
img.Save(Server.MapPath("test2.gif"));

-------catch捕获的错误:
System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。 at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) at test.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\webform2.aspx.cs:line 61
-------
这是什么原因?我先以为权限不够,可将iis里的虚拟目录的“写入”勾上还是不行。
...全文
87 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
暗石绿 2004-08-05
-------catch捕获的错误:
System.Runtime.InteropServices.ExternalException: GDI+ 中发生一般性错误。 at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) at test.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\webform2.aspx.cs:line 61
-------
这是什么原因?我先以为权限不够,可将iis里的虚拟目录的“写入”勾上还是不行。


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

确实是权限不够的原因。
我估计你 iis 的虚拟目录指向的文件夹是在 NTFS 格式的硬盘上的。
如 iis 的虚拟目录指向的文件夹名为 LocalHost

应该是右击 LocalHost ,在“共亨与安全”属性里选中“安全”选项卡,添加 aspnet 用户,给 aspnet 用户添加全权。
回复
quou2002 2004-08-04
nnh(菲一打),首先,你那一行:
dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
有误,应该是:
dim strFileFolder as string =Server.MapPath("../uploadfile_ok/1/")

其次,我问的是Image的Save方法为什么这里会出错。还是不解阿!!!
回复
nnh 2004-08-04
<%@ Import Namespace="System.IO" %>
<%@ page Language="vb" debug="true" codepage="936"%>
<html><head><title>UpLoadFile_VB.aspx</title>
<script language="vb" runat="server">
Sub UploadFile(sender as object ,E as EventArgs)
if not myFile.PostedFile is Nothing then
dim PicSize as string=myFile.PostedFile.ContentLength.ToString()

dim strFileName as string =myFile.PostedFile.FileName.ToString()


dim namei as integer =strFileName.LastIndexOf(".")
dim strNameX as string=strFileName.Substring(namei)
'Set another file name
dim strNewName as string =Request.UserHostAddress.ToString()+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+strNameX

dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
dim strNewFilePath as string =strFileFolder+strNewName

myFile.PostedFile.SaveAs(strNewFilePath)

name.Text=strFileName
fname.Text=myFile.PostedFile.FileName
fenc.Text=myFile.PostedFile.ContentType
fsize.Text=myFile.PostedFile.ContentLength.ToString()
name_cc.Text=strNameX
filesaveto.Text=strNewFilePath
newfilename.Text=strNewName
end if
End Sub
</script>
</head>
<body>
<center>
<h3> UpLoad Files By VB_NET_5 </h3>
<form id="uploderform" method="post" action="uploadfile_c_5.aspx" enctype="multipart/form-data" runat="server" >
<table border="1" cellspacing="0" cellpadding="0" >
<tr> <td><h5>Select File</h5></td</tr>
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="1" cellspacing="0" width="500">
<tr>
<td width="200">Filename:</td>
<td><asp:label id="name" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="name_cc" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fname" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="filesaveto" text="" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fenc" runat="server" />
</td></tr>
<tr>
<td></td>
<td><asp:label id="fsize" runat="server" />
<tr>
<td></td>
<td><asp:label id="newfilename" runat="server" />
</td></tr>
</td></tr>
</table>
</center>
</body>
</html>
回复
quou2002 2004-08-04
请问你们通常是如何保存图片的?
回复
发动态
发帖子
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
社区公告
暂无公告