图像保存时遇到问题!
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里的虚拟目录的“写入”勾上还是不行。
问题点数:10、回复次数:4Top
1 楼quou2002(曲欧)回复于 2004-08-04 13:57:08 得分 0
请问你们通常是如何保存图片的?Top
2 楼nnh(菲一打)回复于 2004-08-04 14:27:48 得分 5
<%@ 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>
Top
3 楼quou2002(曲欧)回复于 2004-08-04 18:12:43 得分 0
nnh(菲一打),首先,你那一行:
dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
有误,应该是:
dim strFileFolder as string =Server.MapPath("../uploadfile_ok/1/")
其次,我问的是Image的Save方法为什么这里会出错。还是不解阿!!!Top
4 楼xrascal(横刀夺爱)回复于 2004-08-05 08:59:47 得分 5
-------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 用户添加全权。Top




