This is default page code:
protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
{
GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
string fileName = args.FileName;
int attachmentId = (int)args.AttachmentKeyValues["ProjectFileId"];
ProTrakEntities objEntity = new ProTrakEntities();
ProjectFile objFile = (from type in objEntity.ProjectFiles where type.ProjectFileId == attachmentId select type).First();
string filename = objFile.FileName;
string Filetype = objFile.FileType;
byte[] binaryData = (byte[])objFile.FileData;
Response.Clear();
Response.ContentType = Filetype;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(binaryData);
Response.End();
}
}
**Uploaded file Code**
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
if (Session["ProjectId"] != null)
{
int Projectid = Convert.ToInt32(Session["ProjectId"]);
string Description = (DetailsView1.FindControl("RadEditor1") as RadEditor).Content;
RadAsyncUpload radAsyncUpload = DetailsView1.FindControl("RadAsyncUpload1") as RadAsyncUpload;
UploadedFile file = radAsyncUpload.UploadedFiles[0];
string s = file.FileName;
string path = System.IO.Path.GetFileName(s);
string Contenttype = radAsyncUpload.UploadedFiles[0].ContentType;
int fileSize = radAsyncUpload.UploadedFiles[0].ContentLength;
float length = float.Parse(fileSize.ToString());
byte[] fileData = new byte[file.InputStream.Length];
file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
ProTrakEntities objEntity = new ProTrakEntities();
ProjectFile objFile = new ProjectFile();
objFile.ProjectId = Projectid;
objFile.FileName = s;
objFile.FileType = Contenttype;
objFile.FileSize = length;
objFile.CreatedBy = "admin";
objFile.CreatedDate = DateTime.Now;
objFile.Description = Description;
objFile.FileData = fileData;
objEntity.AddToProjectFiles(objFile);
objEntity.SaveChanges();
}
}
}
I'm saving the data in database in binaryfromat.i data was not downloading from sever when i click the attachmentcolumn.
protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
{
GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
string fileName = args.FileName;
int attachmentId = (int)args.AttachmentKeyValues["ProjectFileId"];
ProTrakEntities objEntity = new ProTrakEntities();
ProjectFile objFile = (from type in objEntity.ProjectFiles where type.ProjectFileId == attachmentId select type).First();
string filename = objFile.FileName;
string Filetype = objFile.FileType;
byte[] binaryData = (byte[])objFile.FileData;
Response.Clear();
Response.ContentType = Filetype;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(binaryData);
Response.End();
}
}
**Uploaded file Code**
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
if (Session["ProjectId"] != null)
{
int Projectid = Convert.ToInt32(Session["ProjectId"]);
string Description = (DetailsView1.FindControl("RadEditor1") as RadEditor).Content;
RadAsyncUpload radAsyncUpload = DetailsView1.FindControl("RadAsyncUpload1") as RadAsyncUpload;
UploadedFile file = radAsyncUpload.UploadedFiles[0];
string s = file.FileName;
string path = System.IO.Path.GetFileName(s);
string Contenttype = radAsyncUpload.UploadedFiles[0].ContentType;
int fileSize = radAsyncUpload.UploadedFiles[0].ContentLength;
float length = float.Parse(fileSize.ToString());
byte[] fileData = new byte[file.InputStream.Length];
file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
ProTrakEntities objEntity = new ProTrakEntities();
ProjectFile objFile = new ProjectFile();
objFile.ProjectId = Projectid;
objFile.FileName = s;
objFile.FileType = Contenttype;
objFile.FileSize = length;
objFile.CreatedBy = "admin";
objFile.CreatedDate = DateTime.Now;
objFile.Description = Description;
objFile.FileData = fileData;
objEntity.AddToProjectFiles(objFile);
objEntity.SaveChanges();
}
}
}
I'm saving the data in database in binaryfromat.i data was not downloading from sever when i click the attachmentcolumn.