Click here to Skip to main content
11,720,364 members (73,447 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi all,
Please help me,
i have issue on server, my application have file upload control it work fine on local machine but on server its not work proper. in my application have functionality like, user upload all types of file from file upload control and user can replace the file. when user want's to replace file then in my application asked to user for "replace the existing file with new file" if user says "Yes". In application existing file will delete and new file will copy. it also work on server but issue comes when first uploaded file size is small and replacing file size is big then its not work.

Thanks in advance,
protected void btnUpload_Click(object sender, EventArgs e)
       {
           Button btn = (Button)sender;
           int Flag = 0;
           string FileName = createNameForFile(btn.CommandArgument);//Returns Created File Name For the Question.
           Session["QuestionId"] = btn.CommandArgument;
           for (int i = 0; i < dtlViewDetails.Controls.Count; i++)
           {
               DataList DataList2 = (DataList)dtlViewDetails.Controls[i].FindControl("DataList2");
               for (int j = 0; j < DataList2.Controls.Count; j++)
               {
                   Label QuestionId = (Label)DataList2.Controls[j].FindControl("lblQuestionId");
 
                   Label lblHiddenFileName = (Label)DataList2.Controls[j].FindControl("lblHiddenFileName");
                   FileUpload Uploader = (FileUpload)DataList2.Controls[j].FindControl("fuAttachment");
                   LinkButton lnkView = (LinkButton)DataList2.Controls[j].FindControl("lnkView");
                   TextBox txtAnswerTypeDesc = (TextBox)DataList2.Controls[j].FindControl("txtAnswerTypeDesc");
                   Label lblerrorMessageHtmlCell = (Label)DataList2.Controls[j].FindControl("lblerrorMessageHtmlCell");
                   TextBox txtAttachFileDesc = (TextBox)DataList2.Controls[j].FindControl("txtAttachFileDesc");
 
                   if (lblHiddenFileName.Text == "")
                   {
                       if (Convert.ToInt32(QuestionId.Text) == Convert.ToInt32(btn.CommandArgument))
                       {
                           if (Uploader.HasFile)
                           {
                               lblerrorMessageHtmlCell.Visible = false;
                               FileInfo filedet = new FileInfo(Uploader.FileName);
                               string FileNameToCheck = Server.MapPath(DocumentPath + FileName) + filedet.Extension;
                               Uploader.SaveAs(Server.MapPath(DocumentPath + Uploader.FileName));
                               string OriginalName = Server.MapPath(DocumentPath + Uploader.FileName);
                               File.Copy(OriginalName, FileNameToCheck);
                               File.Delete(OriginalName);
                               lblHiddenFileName.Text = FileName + filedet.Extension;
                               lnkView.Visible = true;
                               Flag = 1;
                               break;
                           }
                           else
                           {
                               lblerrorMessageHtmlCell.Visible = true;
                               lblerrorMessageHtmlCell.Text = "No File To Upload.";
                               lblerrorMessageHtmlCell.ForeColor = System.Drawing.Color.Red;
                               Flag = 1;
                               break;
                           }
                       }
                   }
                   else
                   {
                       if (Uploader.HasFile)
                       {
                           lblerrorMessageHtmlCell.Visible = false;
                           Session["FileUploadObject"] = Uploader;
                           Session["FileNameToCheck"] = FileName;
                           Session["LabelFileName"] = lblHiddenFileName.Text;
                           trQuestionaries.Visible = false;
                           trPopupYesNo.Visible = true;
                           //Console.Beep(600, 300);
                       }
                       else
                       {
                           if (Convert.ToInt32(QuestionId.Text) == Convert.ToInt32(btn.CommandArgument))
                           {
                               lblerrorMessageHtmlCell.Visible = true;
                               lblerrorMessageHtmlCell.Text = "No File To Upload.";
                               lblerrorMessag
Posted 19-Feb-13 19:41pm
dA.d577
Edited 20-Feb-13 10:03am
v2
Comments
Asim Mahmood at 20-Feb-13 1:50am
   
what's file size you are uploading
dA.d at 20-Feb-13 2:16am
   
Thanks for replay..
115kb size file, but when i upload as first time its work.
Asim Mahmood at 20-Feb-13 2:18am
   
may you please share your code?
dA.d at 20-Feb-13 2:23am
   
yes..code of two button which i used as below:

protected void btnUpload_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
int Flag = 0;
string FileName = createNameForFile(btn.CommandArgument);//Returns Created File Name For the Question.
Session["QuestionId"] = btn.CommandArgument;
for (int i = 0; i < dtlViewDetails.Controls.Count; i++)
{
DataList DataList2 = (DataList)dtlViewDetails.Controls[i].FindControl("DataList2");
for (int j = 0; j < DataList2.Controls.Count; j++)
{
Label QuestionId = (Label)DataList2.Controls[j].FindControl("lblQuestionId");

Label lblHiddenFileName = (Label)DataList2.Controls[j].FindControl("lblHiddenFileName");
FileUpload Uploader = (FileUpload)DataList2.Controls[j].FindControl("fuAttachment");
LinkButton lnkView = (LinkButton)DataList2.Controls[j].FindControl("lnkView");
TextBox txtAnswerTypeDesc = (TextBox)DataList2.Controls[j].FindControl("txtAnswerTypeDesc");
Label lblerrorMessageHtmlCell = (Label)DataList2.Controls[j].FindControl("lblerrorMessageHtmlCell");
TextBox txtAttachFileDesc = (TextBox)DataList2.Controls[j].FindControl("txtAttachFileDesc");

if (lblHiddenFileName.Text == "")
{
if (Convert.ToInt32(QuestionId.Text) == Convert.ToInt32(btn.CommandArgument))
{
if (Uploader.HasFile)
{
lblerrorMessageHtmlCell.Visible = false;
FileInfo filedet = new FileInfo(Uploader.FileName);
string FileNameToCheck = Server.MapPath(DocumentPath + FileName) + filedet.Extension;
Uploader.SaveAs(Server.MapPath(DocumentPath + Uploader.FileName));
string OriginalName = Server.MapPath(DocumentPath + Uploader.FileName);
File.Copy(OriginalName, FileNameToCheck);
File.Delete(OriginalName);
lblHiddenFileName.Text = FileName + filedet.Extension;
lnkView.Visible = true;
Flag = 1;
break;
}
else
{
lblerrorMessageHtmlCell.Visible = true;
lblerrorMessageHtmlCell.Text = "No File To Upload.";
lblerrorMessageHtmlCell.ForeColor = System.Drawing.Color.Red;
Flag = 1;
break;
}
}
}
else
{
if (Uploader.HasFile)
{
lblerrorMessageHtmlCell.Visible = false;
Session["FileUploadObject"] = Uploader;
Session["FileNameToCheck"] = FileName;
Session["LabelFileName"] = lblHiddenFileName.Text;
trQuestionaries.Visible = false;
trPopupYesNo.Visible = true;
//Console.Beep(600, 300);
}
else
{
if (Convert.ToInt32(QuestionId.Text) == Convert.ToInt32(btn.CommandArgument))
{
lblerrorMessageHtmlCell.Visible = true;
lblerrorMessageHtmlCell.Text = "No File To Upload.";
lblerrorMessag
Edo Tzumer at 20-Feb-13 4:44am
   
Share the code on the question above (you can edit your question) rather than on the thread here
Shubh Agrahari at 25-Feb-13 1:38am
   
any exception or error getting or not...like error code. HTTP 400...?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi buddy..

there can be many issues that restricting your file from moving to server....may IIS settings or executionTimeout and maxRequestLength setting that may have to done in your web.config file.....but overall
go throw this link that may help you to achieve your task....

http://aspnetresources.com/articles/dark_side_of_file_uploads[^]


Happy to help.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It depends on your Server dude you can't upload file size more than 2 mb in laamp server
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 2,029
1 OriginalGriff 844
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100