Dear Sir,
I have some problems when i am implemented code in the download attachment. The Problem is if i am attached file in 150 kb then i am download this file he gives me
60 kb only. The properly not download any attachment file and if any data saved on it then you have download this file not given any data or blanck data give me this document. So could you please suggest me.
Thanks in Advanced !!
protected void DownloadAttachmentCompany()
{
string obj_attachmentFilename;
cls_bl_Company obj = new cls_bl_Company();
mstr_ConnectionString = Session[SessionController.SESSION_CONSTRING].ToString();
mint_LanguageId = Convert.ToInt32(Session[SessionController.SESSION_LANGID].ToString());
mobj_company = new clsCompany(mstr_ConnectionString);
int int_ClientId = Convert.ToInt32(Session[SessionController.SESSION_CLIENTID]);
int int_CompanyId = Convert.ToInt32(Session[SessionController.SESSION_LOADEDCOMPANY]);
int AttachmentId = Convert.ToInt32(aspLstBox.SelectedValue);
obj_attachmentFilename = mobj_company.getattachmentfilename(AttachmentId , int_CompanyId, int_ClientId);
string filePath = Server.MapPath("~/Attachments/");
string _DownloadableProductFileName = obj_attachmentFilename;
string strFileexits = filePath + _DownloadableProductFileName;
System.IO.FileInfo FileName = new System.IO.FileInfo(filePath + _DownloadableProductFileName);
if (File.Exists(strFileexits))
{
FileStream myFile = new FileStream(filePath + "//" + _DownloadableProductFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite,FileShare.ReadWrite);
BinaryReader _BinaryReader = new BinaryReader(myFile);
long startBytes = 0;
string lastUpdateTiemStamp = File.GetLastWriteTimeUtc(filePath).ToString("r");
string _EncodedData = HttpUtility.UrlEncode
(_DownloadableProductFileName, Encoding.UTF8) + lastUpdateTiemStamp;
Response.Clear();
Response.Buffer = false;
Response.AddHeader("Accept-Ranges", "bytes");
Response.AppendHeader("ETag", "\"" + _EncodedData + "\"");
Response.AppendHeader("Last-Modified", lastUpdateTiemStamp);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name);
Response.AddHeader("Content-Length", (FileName.Length - startBytes).ToString());
Response.AddHeader("Connection", "Keep-Alive");
Response.ContentEncoding = Encoding.UTF8;
_BinaryReader.BaseStream.Seek(startBytes, SeekOrigin.Begin);
}
else
{
MessageBox.Show("File does not Exits");
}
this.EnableModelDialog(true);
}
protected void LoadAttachmentHeaderAssigenment()
{
cls_bl_Assignment[] objary_AttachmentText = new cls_bl_Assignment[25];
clsAssignment mobj_Assigenment = new clsAssignment(mstr_ConnectionString);
int int_ClientId = Convert.ToInt32(Session[SessionController.SESSION_CLIENTID]);
int int_AssigenmentId = Convert.ToInt32(Session[SessionController.SESSION_LOADEDASSIGNMENT]);
objary_AttachmentText = mobj_Assigenment.LoadAttachmentHeaderAssigenment(int_AssigenmentId, int_ClientId);
int intGotIndex = 0;
if (Page.IsPostBack)
{
aspLstBox.Items.Clear();
if (null != objary_AttachmentText)
{
for (int forcount = 0; forcount < objary_AttachmentText.Length; forcount++)
{
intGotIndex = 0;
for (int intforcount = 0; intforcount < aspLstBox.Items.Count; intforcount++)
{
if (objary_AttachmentText[forcount].Text == aspLstBox.Items[intforcount].Text)
{
intGotIndex = 1;
}
}
if (0 == intGotIndex)
{
aspLstBox.Items.Add(new ListItem(objary_AttachmentText[forcount].Text.ToString(), objary_AttachmentText[forcount].AttachmentId.ToString()));
}
}
}
}
}
in this code you have added attachment id from list box control and all other id from session control so please give me some improvements in this code.
Thanks in Advanced !!