play
2011-07-02 20:17:23

play

▼ more
우리의 어두운 시기를 함께 해줬던
2011-07-02 11:44:51

... ..

▼ more
filetype asp
2011-07-02 09:52:51

strFileType = lcase(Right(strFileName, 4))

' Feel Free to Add Your Own Content-Types Here

Select Case strFileType

Case ".asf"

ContentType = "video/x-ms-asf"

Case ".avi"

ContentType = "video/avi"

Case ".doc"

ContentType = "application/msword"

Case ".zip"

ContentType = "application/zip"

Case ".xls"

ContentType = "application/vnd.ms-excel"

Case ".gif"

ContentType = "image/gif"

Case ".jpg", "jpeg"

ContentType = "image/jpeg"

Case ".wav"

ContentType = "audio/wav"

Case ".mp3"

ContentType = "audio/mpeg3"

Case ".mpg", "mpeg"

ContentType = "video/mpeg"

Case ".rtf"

ContentType = "application/rtf"

Case ".htm", "html"

ContentType = "text/html"

Case ".asp"

ContentType = "text/asp"

Case Else

'Handle All Other Files

ContentType = "application/octet-stream"

End Select

▼ more
ASP.net 파일 업로드 다운로드
2011-07-02 09:50:56

출처 :

http://hoons.kr/board.aspx?Name=QAASPNET&BoardIdx=16007&Page=1&Mode=2

업로드 로직

/// <summary>

/// 파일을 서버에 저장하는 함수

/// </summary>

/// <param name="fu">파일 업로드 객체</param>

/// <param name="upDir">파일이 저장될 서버상의 경로</param>

/// <returns></returns>

public string saveFile( FileUpload fu, string upDir )

{

  //서버에 디렉토리가 존재하는 확인하고 디렉토리가 없다면 디렉토리 생성

  DirectoryInfo dInfo = new DirectoryInfo(upDir);

  if (!dInfo.Exists)

  {

    dInfo.Create();

  }

   //새로 업로드 할 파일과 동일한 파일명이 서버에 존재 할 경우

  //파일명에 언더바(_)와 함께 순서 번호를 붙여서 파일 중복을 피한다.

  string fileName = fu.FileName; //클라이언트 측 파일 경로가 제거된 순수 파일명

  string fileFullName = upDir + fileName; //업로드될 서버측 경로와 파일명

  FileInfo fInfo = new FileInfo(fileFullName);

  string newFileName = string.Empty; //파일 중복을 피하기위해 새로 생성된 파일명

  //서버에 같은 이름의 파일이 존재 하는지 확인

  if (fInfo.Exists)

  {

    //같은 이름의 파일이 있다면

    int fIndex = 0; //파일 순서

    string fExtension = fInfo.Extension; //파일의 확장자 추출

    string fRealName = fileName.Replace(fExtension, ""); //파일명의 확장자 제거

    //파일명이 중복되지 않을때까지 루프를 돌면서 검사

    do

    {

      fIndex++;//파일 번호 증가

      //새로운 파일 이름 (확장자 제거된 파일명 + _ + 순서번호 + 확장자)

      newFileName = fRealName + "_" + fIndex.ToString() + fExtension;

      //새로운 파일 이름으로 파일정보 생성

       fInfo = new FileInfo(upDir + newFileName);

    } while (fInfo.Exists); //파일이 존재 한다면 다시 반복

    fileFullName = upDir + newFileName; //서버측 업로드 경로 + 새로운 파일명

    fu.PostedFile.SaveAs(fileFullName); //만들어진 경로와 파일명으로 파일을 서버측에 업로드

    return newFileName; //새로 만들어진 파일명 만 반환

  }

  else

  {

    //같은 이름의 파일이 없다면

    fu.PostedFile.SaveAs(fileFullName); //최초 정해진 경로와 파일명으로 서버측에 업로드

    return fileName; //파일명 반환

  }

}

다운로드 로직

/// <summary>

/// 파일 다운로드 하기

/// </summary>

/// <param name="fileName">다운로드할 파일명</param>

/// <param name="fileDir">파일이 위치한 서버측 경로</param>

protected void downFile( string fileName, string fileDir )

{

  string downPath = fileDir + fileName;

  if ( File.Exists( downPath ) )

  {

    Response.Clear();

    Response.AddHeader("Content-Disposition", "attachment;filename="

                         + Server.UrlEncode( fileName ).Replace( "+", "%20" ) );

    Response.ContentType = "application/octet-stream";

    Response.TransmitFile( downPath );

Response.End()

  }

}

[출\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\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