mmm... using System.Drawing, c'era già. La cosa strana è che se per scrupolo lo aggiungo davanti ad imaging quando compilo mi esce un messaggio di errore:
Error while tryning to run project. Unable to start debugging on the web server. Server side-error occurred on sendig debug HTTP.
Poi va bè, la seconda parte penso sia irrilevante, dice di controllare il web config...
Mio codice:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace upload2
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile Lfile;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Msg;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
if ((! (Lfile.PostedFile == null)) && (Lfile.PostedFile.ContentType.Substring(0, 5) == "image"))
{
HttpImgUpload objUpload = new HttpImgUpload (Lfile.PostedFile, System.Configuration.ConfigurationSettings.AppSettings["UploadFolder"], "test.jpg", 250000, 300, 300);
objUpload.DestinationFolder = System.Configuration.ConfigurationSettings.AppSettings["UploadFolder"]; // opzionale
objUpload.ImageFilename = "test.jpg"; // opzionale
objUpload.Format = System.Drawing.Imaging.ImageFormat.Jpeg; // opzionale
objUpload.SaveImage();
}
else
{
// intercetto l'errore e lo metto sulla label
}
}
catch
{
// eccezione 1
}
finally
{
// eccezione2
}
}
}
}
Web Config che non ho toccato:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<AppSettings>
<add key="UploadFolder" value="myPath" />
</AppSettings>
<system.web>
<system.web>
<compilation
defaultLanguage="c#"
debug="true"
/>
<customErrors
mode="RemoteOnly"
/>
<authentication mode="Windows" />
<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
</system.web>
</configuration>