Q:

login to site and download a file?

I have implanted a login code to a site  , after that I want to download a file from a server . 
    HttpWebRequest http = WebRequest.Create(@"http://www.website.com") as HttpWebRequest;
    //    http.Connection = "Keep-alive"; //uncertain
    http.Method = "POST";
    http.ContentType = "application/x-www-form-urlencoded";
    string postData = "FormNameForUserId=" + @"username" + "&FormNameForPassword=" + "pass";
    byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
    http.ContentLength = dataBytes.Length;
    using (Stream postStream = http.GetRequestStream())
    {
        postStream.Write(dataBytes, 0, dataBytes.Length);
    }
    HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;
    // Probably want to inspect the http.Headers here first
    http = WebRequest.Create(@"http://www.codeproject.com") as HttpWebRequest;
    http.CookieContainer = new CookieContainer();
    http.CookieContainer.Add(httpResponse.Cookies);
    HttpWebResponse httpResponse2 = http.GetResponse() as HttpWebResponse;

How can I find out I have loged in correctly , also What should I do after login to download a file ?

A:

You have two issues

Login
Download File

Did you ever Google this?

Login
Download File | Download File | Download File

Note: You said you already implemented a login page ... the easiest part is set a session variable after the login is done and for every page recheck that variable.
This is the old way, there is plenty more we can do, but form your questions, please go with this:
if( txtUsername.Text == "user" && txtPassword.Text == "pwd" ) { 
    // Login correct
    Session["Login-User"] = txtUsername.Text;
} 
else {
    // Login not correct, show error message and clear session
    Session["Login-User"] = "";
}

then in any page, at the beginning (best placed in Page_Init method)
If( Session["Login-user"] != null && Session["Login-user"].ToString().Length > 0 ) {
    // Login OK
}
else {
    // Login Not OK, redirect
    Response.Redirect("~/Login.aspx");
}

Learn more in ASP.NET official website

