Friday, February 19, 2010

Find GridView Row And DataKey Value

Dim row As GridViewRow = DirectCast((DirectCast(e.CommandSource, LinkButton).NamingContainer), GridViewRow)
Dim RollNo As Integer
RollNo = CInt(MyGridView.DataKeys(row.RowIndex).Value)

Monday, February 15, 2010

Download File From FTP

Response.Buffer = true;
Response.Clear();


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

Response.Flush();
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(FullFilePath));

reqFTP.Proxy = null;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("userid", "password");



WebResponse aa = reqFTP.GetResponse();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
MemoryStream MemStream = new MemoryStream();
int bufferSize = 2048;
byte[] respBuffer = new byte[bufferSize];
try
{
int bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length);

while (bytesRead > 0)
{
MemStream.Write(respBuffer, 0, bytesRead);
bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length);

}
byte[] finalByte = MemStream.GetBuffer();
Response.BinaryWrite(finalByte);