skymong9.egloos.com

Activation...

포토로그



[ASP.NET] 다중파일 업로드하기 my dev_study

다중파일 업로드 샘플

[default.aspx]
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>제목 없음</title>
</head>
<body>
    <form id="form1" action="default_i.aspx" method="post" enctype="multipart/form-data">
    <input type="file" name="file1" />
    <input type="file" name="file2" />
    <input type="submit" value="전송" />
    </form>
</body>
</html>

[default_i.aspx]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default_i.aspx.cs" Inherits="default_i" %>
<%
  default_i product_ins_i = new default_i();
  string sSavePath = "./PRODIMG_FILES/";
   string filepath = Server.MapPath(sSavePath);
   HttpFileCollection uploadedFiles = Request.Files;
   HttpPostedFile MyFile;

   HttpFileCollection MyFileCollection;
   for (int i = 0; i < uploadedFiles.Count; i++)
   {
     HttpPostedFile userPostedFile = uploadedFiles[i];
     MyFile = uploadedFiles[i];

     try
     {
       if (userPostedFile.ContentLength > 0)
       {
         string sFilename = System.IO.Path.GetFileName(MyFile.FileName);
         int file_append = 0;
         while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
         {
           file_append++;
           sFilename = System.IO.Path.GetFileNameWithoutExtension(MyFile.FileName) + file_append.ToString() + ".jpg";
           Response.Write(sFilename);
         }
         userPostedFile.SaveAs(filepath + "\\" + sFilename);

       }
     }
     catch (Exception Ex)
     {
       Response.Write("Error: " + Ex.Message);   
     }
   }
%>


덧글

댓글 입력 영역