2010-05-19 62 views
0

我有點健忘 已經取得了很多次,並且不能找到我最後一次做它的代碼 我得到它如何來調整多張圖片如何調整圖像

我喜歡這

Guid imageName; 
imageName = Guid.NewGuid(); 
string storePath = Server.MapPath("~") + "/MultipleUpload"; 
if (!Directory.Exists(storePath)) 
    Directory.CreateDirectory(storePath); 
hif.PostedFile.SaveAs(storePath + "/" + Path.GetFileName(hif.PostedFile.FileName)); 

string tempPath = "Gallery"; 
string imgPath = "Galleryt"; 
string savePath = Path.Combine(Request.PhysicalApplicationPath, tempPath); 
string TempImagesPath = Path.Combine(savePath, imageName + hif.PostedFile.FileName); 
string imgSavePath = Path.Combine(Request.PhysicalApplicationPath, imgPath); 
string ProductImageNormal = Path.Combine(imgSavePath, "t__" + imageName + hif.PostedFile.FileName); 
string extension = Path.GetExtension(hif.PostedFile.FileName); 
switch (extension.ToLower()) 
    { 
     case ".png": goto case "Upload"; 
     case ".gif": goto case "Upload"; 
     case ".jpg": goto case "Upload"; 
     case "Upload": hif.PostedFile.SaveAs(TempImagesPath); 
      ImageTools.GenerateThumbnail(TempImagesPath, ProductImageNormal, 250, 350, true, "heigh"); 
      Label1.Text = ""; 
      break; 
    } 
+5

也許使用循環... – 2010-05-19 08:42:25

+0

任何人爲SOC/SRP? – 2010-05-19 09:35:23

+0

'e'標籤的用途是什麼? – RichK 2010-05-19 10:23:15

回答

0

我發現自己 但還是謝謝你爲尋找

但現在我有一個問題 我不會保留原文件應該再次刪除,當它完成調整 如果我只是

File.Delete(Server.MapPath("~/Gallery/" + imageName + hif.PostedFile.FileName)); 

後立即刪除它的代碼,以便它說,它不能刪除該文件,因爲它是在頁面上被另一個進程使用。

     string storePath = Server.MapPath("~") + "/MultipleUpload"; 
         if (!Directory.Exists(storePath)) 
          Directory.CreateDirectory(storePath); 

         string tempPath = "Galleryt"; 
         string imgPath = "Gallery"; 
         string savePath = Path.Combine(Request.PhysicalApplicationPath, tempPath); 
         string imgSavePath = Path.Combine(Request.PhysicalApplicationPath, imgPath); 
         string imgSavePath2 = Path.Combine(Request.PhysicalApplicationPath, imgPath); 
         string ProductImageNormal = Path.Combine(imgSavePath, imageName + hif.PostedFile.FileName); 
         string ProductImagetemp = Path.Combine(savePath, "t__" + imageName + hif.PostedFile.FileName); 
         string ProductImagetemp2 = Path.Combine(imgSavePath2, "b__" + imageName + hif.PostedFile.FileName); 
         string extension = Path.GetExtension(hif.PostedFile.FileName); 

         switch (extension.ToLower()) 
         { 
          case ".png": goto case "Upload"; 
          case ".gif": goto case "Upload"; 
          case ".jpg": goto case "Upload"; 
          case "Upload": hif.PostedFile.SaveAs(ProductImageNormal); 
           ImageTools.GenerateThumbnail(ProductImageNormal, ProductImagetemp, 600, 600, true, "heigh"); 
           ImageTools.GenerateThumbnail(ProductImageNormal, ProductImagetemp2, 250, 350, true, "heigh"); 

           Label1.Text = ""; 
           break; 
          default: 
           Label1.Text = "Status: Denne filtype er ikke tilladt"; 
           return; 

         }