服务器上的文件上传问题 [英] file upload issue on server

查看:74
本文介绍了服务器上的文件上传问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请帮助我,

i在服务器上有问题,我的应用程序有文件上传控制它在本地机器上工作正常但在服务器上它不能正常工作。在我的应用程序中有类似的功能,用户从文件上传控件上传所有类型的文件,用户可以替换该文件。当用户想要替换文件时,如果用户说是,则在我的应用程序中向用户询问用新文件替换现有文件。在应用程序中,现有文件将被删除,新文件将被复制。它也可以在服务器上运行,但问题是当第一个上传的文件很小并且替换文件大小很大然后它不起作用。



提前谢谢,

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

推荐答案

hi buddy ..



可能存在许多限制文件移动到服务器的问题....可能在您的web.config文件中可能需要进行IIS设置或executionTimeout和maxRequestLength设置.....但总体而言

去抛出这个链接,可以帮助你完成任务....



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





乐于助人。
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.


这取决于你的服务器老兄你不能在laamp服务器上传文件大小超过2 mb
It depends on your Server dude you can''t upload file size more than 2 mb in laamp server


这篇关于服务器上的文件上传问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆