Feb 11, 2011, 9:05 AM
[CLOSED] Dynamic FileUploadField, Response opens the file save(download) box
Hi, there
Pleas would you help me out, I have two issues regarding File Upload.
I have a form panel where I want to add dynamic FileUploadFields but since I couldnt be able to add them dynamically on client side I wrote them statically.
2-) On server side I set IsUpload to true but if the user doesnt upload at least one document, the response isn't displayed instead it opens the file download box to be saved.
Here is my server side code:
Pleas would you help me out, I have two issues regarding File Upload.
I have a form panel where I want to add dynamic FileUploadFields but since I couldnt be able to add them dynamically on client side I wrote them statically.
<ext:Container ID="Container3" runat="server" LabelAlign="Top" Layout="Form" ColumnWidth=".5">
<Items>
<ext:FileUploadField ID="FileUploadField1" runat="server" FieldLabel="Attachments" width="250" Icon="Attach" />
<ext:FileUploadField ID="FileUploadField2" runat="server" width="250" Icon="Attach" />
<ext:FileUploadField ID="FileUploadField3" runat="server" width="250" Icon="Attach" >
</Items>
</ext:Container>
1-) How can I add those FileUploadField dynamically. So one FileUploadField will be by default and the others to be like "add new file" 2-) On server side I set IsUpload to true but if the user doesnt upload at least one document, the response isn't displayed instead it opens the file download box to be saved.
Here is my server side code:
public AjaxFormResult SaveReport(FormCollection values)
{
AjaxFormResult afr = new AjaxFormResult();
Dijt di = new Dijt();
di.App_User_ID = Convert.ToInt32(Session["uid"].ToString());
di.ContentDate = DateTime.Now;
this.DBContext.Dijts.InsertOnSubmit(di);
try{
this.DBContext.SubmitChanges();
Attachment at;
bool hasfile = false;
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength > 0)
{
afr.IsUpload = true;
hasfile = true;
at = new Attachment();
string savedFileName = Path.Combine(HttpContext.Server.MapPath("~/Attachments"), Path.GetFileName(hpf.FileName););
hpf.SaveAs(savedFileName);
at.Referal_ID = di.DijtID;
at.Attachment1 = savedFileName;
this.DBContext.Attachments.InsertOnSubmit(at);
}
}
if (hasfile)
{
try
{
this.DBContext.SubmitChanges();
afr.Success = true;
afr.ExtraParams["feedback"] = "Raport is saved succesfully";
}
catch (Exception e)
{
afr.Success = false;
afr.ExtraParams["msg"] = e.ToString();
afr.ExtraParams["responseText"] = "The report is saved, but there has been an error saving your files!";
}
}
else
{
afr.Success = true;
afr.IsUpload = false;
afr.ExtraParams["feedback"] = "Raport is saved succesfully";
}
}
catch(Exception e){
afr.Success = false;
afr.ExtraParams["msg"] = e.ToString();
afr.ExtraParams["responseText"] = "There has been an error on saving your report";
}
return afr;
}
Thank you,
Last edited by Daniil; Feb 14, 2011 at 7:17 AM.
Reason: [CLOSED]