반응형
//========================================
//↓↓ASP.NET1.1에서 파일업로드
//========================================
protected void saveFile()
{
string FileName = FileUpload.PostedFile.FileName;
if (FileName != null || FileName != string.Empty)
{
Session["myupload"] = FileUpload;
}
HtmlInputFile hif = (HtmlInputFile)Session["myupload"];
string storePath = "d:\\momo13";
if (Directory.Exists(storePath))
Directory.CreateDirectory(storePath);
hif.PostedFile.SaveAs(storePath + "/" + Path.GetFileName(hif.PostedFile.FileName));
lblMsg.Text = "업로드";
}
//========================================
//↓↓ASP.NET2.0에서 파일업로드
//========================================
protected void saves1()
{
if (FileUpload1.HasFile)
{
DirectoryInfo di = new DirectoryInfo(upDir);
if (!di.Exists)
di.Create();
string fName = FileUpload1.FileName;
string fFullName = upDir + fName;
FileInfo fInfo = new FileInfo(fFullName);
if (fInfo.Exists)
{
int fIndex = 0;
string fExtension = fInfo.Extension;
string fRealName = fName.Replace(fExtension, "");
string newFileName = "";
do
{
fIndex++;
newFileName = fRealName + "_" + fIndex.ToString() + fExtension;
fInfo = new FileInfo(upDir + "\\" + newFileName);
}
while (fInfo.Exists);
fFullName = upDir + "\\" + newFileName;
}
FileUpload1.PostedFile.SaveAs(fFullName);
lblMsg.Text = "업로드된 파일 : " + fFullName;
}
else
{
lblMsg.Text = "업로드할 파일이 존재하지 않습니다.";
}
}