Torna al Thread

void UploadBtn_Click(Object sender, EventArgs e) { String UploadedFile = MyFile.PostedFile.FileName; int ExtractPos = UploadedFile.LastIndexOf("\\") + 1; //to retrieve only Filename from the complete path String UploadedFileName = UploadedFile.Substring(ExtractPos,UploadedFile.Length - ExtractPos); // Display information about posted file. Div is invisible by default FileName.InnerHtml =UploadedFileName; MyContentType.InnerHtml = MyFile.PostedFile.ContentType; ContentLength.InnerHtml = MyFile.PostedFile.ContentLength.ToString(); FileDetails.Visible = true; //div is made visible // Save uploaded file to server at the in the Pics folder String percorso= Request.PhysicalPath; int daEliminare= percorso.Length -29; string nuovo = percorso.Substring(0, daEliminare) + "foto/"; String idUser= Request.Form["idUser"]; const string FMT = "yyyy-MM-dd"; DateTime now1 = DateTime.Now; string DataTxt = now1.ToString(FMT); DataTxt=DataTxt.Replace("-",""); MyFile.PostedFile.SaveAs(nuovo + idUser+ DataTxt+ UploadedFileName); //thumbnail creation starts try { //Read in the image filename whose thumbnail has to be created String imageUrl= UploadedFileName; //You may even specify a standard thumbnail size int imageWidth = 245; int imageHeight = 184; imageUrl = nuovo + imageUrl; System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(imageUrl); int altezzaNuova; int larghezzaNuova; larghezzaNuova = fullSizeImg.Width * imageHeight / fullSizeImg.Height; System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(larghezzaNuova, imageHeight, dummyCallBack, IntPtr.Zero); string nuovoFileName; string[] words = UploadedFileName.Split('.'); String MyString = "min_" + idUser+ DataTxt +words[0] + ".jpg"; thumbNailImg.Save(nuovo + MyString, ImageFormat.Jpeg); thumbNailImg.Dispose(); } catch(Exception ex) { Response.Write("An error occurred - " + ex.ToString()); } }
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5