반응형
string strSql = "Select * From country_def";
OracleCommand cmd = new OracleCommand(strSql,dbConn.OraConn());
cmd.Connection.Open();
OracleDataReader rd = cmd.ExecuteReader();
dpCountry.DataSource = rd;
dpCountry.DataValueField = "country_cd";
dpCountry.DataTextField = "country_name";
dpCountry.DataBind();
rd.Close();
cmd.Connection.Close();
----------------------------------------------------------------------
기초적인 내용인데 자주 까먹는다. ㅠ_ㅠ
반응형
ASP.NET에서는 Response.WriteFile() 이라는 함수를 이용해서 파일(바이너리)을 스트림으로 내려보낼 수 있다.
사용 방법은 간단하다.

 

    Response.AddHeader("Content-Disposition", "attachment;filename=\"123.zip\"");
    Response.ContentType = "application/octet-stream";

    Response.WriteFile("C:\\123.zip");

 

즉, URL로 접근이 가능하지 않은 파일을 이와 같은 방법을 통해 동적으로 내려보낼 수 있다.
그런데, 이 파일의 크기가 100MB이상의 대용량인 경우에는 웹 서버에서 에러가 발생하고 다운로드가 안될 수 있다.
그럴 때는 아래 링크를 참조하자.

 

http://support.microsoft.com/kb/812406 

반응형
※닷넷에서 한글파라미터는 인식이 되지 않는 경우가 있기 때문에 인코딩 디코딩 해준다.
   특히 띄워쓰기 포함된 한글파라미터는 반드시 인코딩 디코딩 해주어야 한다.

//보내는 쪽 url파라미터
group = HttpUtility.UrlEncode(group);
//받는 쪽 url파라미터
group = HttpUtility.UrlDecode(Request.Params["group"].ToString().Trim());

※참조한 원문 
HttpUtility.UrlEncode("홍길동", System.Text.Encoding.GetEncoding("euc-kr")) 

반응형
// FTP UPLOAD
using System.IO;
using System.Net;

 

/// <summary>
    ///  FTP 업로드
    /// </summary>
    /// <returns></returns>
    private bool Media_FtpUpload()
    {
        try
        {
            string strFTP_URL = @"ftp://123.123.123.123:1234/";
            string strFTP_ID = "id";
            string strFTP_PW = "pw";

            // 선택파일의 이진 데이터 생성
            byte[] fileData = new byte[file1.PostedFile.ContentLength];

            // 파일정보를 바이너리에 저장
            BinaryReader br = new BinaryReader(file1.PostedFile.InputStream);
            br.Read(fileData, 0, fileData.Length);
            br.Close();

            WebClient request = new WebClient();

            // FTP 로 접속
            request.Credentials = new NetworkCredential(strFTP_ID, strFTP_PW);

            // FTP 로 데이터 업로드
            byte[] newFileData = request.UploadData(strFTP_URL + file1.FileName, fileData);

            lblMsg.Text = strFTP_URL + file1.FileName;

            return true;
        }

        catch
        {
            return false;
        }
    }

    /// <summary>
    /// FTP 다운로드
    /// </summary>
    /// <returns></returns>
    private bool Media_FtpDownload()
    {
        try
        {
            string strFTP_URL = @"ftp://123.123.123.123:1234/";
            string strFTP_ID = "id";
            string strFTP_PW = "pw";

            WebClient request = new WebClient();

            request.Credentials = new NetworkCredential(strFTP_ID, strFTP_PW);

            // FTP 로 부터 데이터 다운로드 
            byte[] newFileData = request.DownloadData(lblMsg.Text);

            string strFileName = lblMsg.Text.Substring(lblMsg.Text.LastIndexOf("/") + 1);

            // 특정 폴더로 파일생성
            FileStream newFile = new FileStream(@"C:\media\" + strFileName, FileMode.Create);

            // 파일쓰기
            newFile.Write(newFileData, 0, newFileData.Length);

            // 파일닫기
            newFile.Close();

            return true;
        }
        catch
        {
            return false;
        }
    }
[출처] [ASP.NET 1.1] FTP 업로드 / 다운로드|작성자 보리
http://blog.naver.com/bori29?Redirect=Log&logNo=130031228382
반응형
//이미지 파일 저장
private void imageCreate(string pathname)
{
string filepath = "";
WebClient clt = new WebClient();
//받아올 경로
string url = imgpath + pathname + "/";
if (Directory.Exists(paths+pathname)==false)
Directory.CreateDirectory(paths+pathname);
clt.DownloadFile(url+aryimg[arycnt],paths + filepath+ aryimg[arycnt]);
}
----------------------------------------------------------------------------
WebClient를 통해서 웹에 공개된 이미지를 다운로드.

+ Recent posts