[파일업로드]

어플리케이션에서 웹서버로 파일전송하기~

app 프로그램 코드

  try
   {
    string stringUrl="http://localhost/FileUpload/Upload.aspx";
    System.Net.WebClient webClient = new System.Net.WebClient();
    byte[] responseArray =webClient.UploadFile(stringUrl , "POST", this.label1.Text);  

/*

System.Text.Encoding.ASCII.GetString(responseArray); 를 실행하면 파일 업로드한 웹페이지를 받아옵니다. 그러타면... 중복파일이 있다면 중복처리를 한다음에  변경된 파일 네임을 돌려주면 되겠따;;;

# System.Text.Encoding.ASCII.GetString(responseArray);  어라 한글깨졌네

아래처럼하니깐 한글이 안깨진다

this.textBox1.Text = System.Text.UTF8Encoding.UTF8.GetString(responseArray);

*/

    this.label2.Text = System.Text.Encoding.ASCII.GetString(responseArray);

   }
   catch(System.Exception error)
   {
    MessageBox.Show( error.ToString() );
   }

http://localhost/FileUpload/Upload.aspx코드

  private void Page_Load(object sender, System.EventArgs e)
  {

    // 여기에 사용자 코드를 배치하여 페이지를 초기화합니다.

foreach(string f in Request.Files.AllKeys)
   {

    HttpPostedFile file = Request.Files[f];
    file.SaveAs(@"C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\GenealogicalWEBSITE\FileUpload\" + file.FileName);

  }

+ Recent posts