Click here to Skip to main content
15,881,863 members

file upload issue on server

dA.d asked:

Open original thread
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
Tags: C#, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900