简体   繁体   中英

The original file is in the temp folder error when uploading a file to IIS server from asp.net web forms project

I am trying to upload some files wtih different extensions like .png,.jpg,.txt,.pdf etc. to IIS server .However my all files are created to given path but they are all 1kb size and when you open them it says

The original file is in the temp folder. Full path of the file: C:\\Temp\\xxxxxxxxx.tmp

My code works perfectly on localhost when running from the source code and There is no such a folder on web server's directory like mentioned in the message.

My code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadTest.aspx.cs" Inherits="FileUploadTest" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
                <asp:FileUpload ID="FileUpload1"  Multiple="Multiple" name="okantestfileupload" runat="server" />
                <asp:Button ID="btnFileUpload" OnClick="btnFileUpload_Clickk" runat="server" Text="ekle" Width="150px" CssClass="CommandButton" />
               <asp:ListBox runat="server" ID="ListBoxForInfo" Width="400" CssClass="NormaltextBox" ></asp:ListBox>
        </div>
    </form>
</body>
</html>

.cs part

protected void btnFileUpload_Clickk(object sender, EventArgs e)
    {
        string strFolder = @"D:\TEST\";
        HttpFileCollection uploadedFiles = Request.Files;

        for (int i = 0; i < uploadedFiles.Count; i++)
        {
            HttpPostedFile uploadedFile = Request.Files.Get(i);


            var uFileSize = uploadedFile.ContentLength;
            var uFileName = uploadedFile.FileName;
            var uContentType = uploadedFile.ContentType;
            string uExtension =
               System.IO.Path.GetExtension(uploadedFile.FileName);

            uploadedFile.SaveAs(strFolder + uFileName);
            ListBoxForInfo.Items.Insert(0, uFileName + "." + uContentType + " Boyut: (" + uFileSize + " bytes)  yüklendi.");


        }
    }

What should I do to fix that?I have already tried some solutions including taking consideration of antivirus programmes.

Regards

The problem was the Managed Pipeline Mode configuration of the related Application Pool.The application was run on v2.0 .NET CLR Version but the project was built on .NET 3.5. So changing the Managed PipeLine Mode from Classic to Integrated solved the problem unintentionally without knowing the detailed mechanism. Probable incompatibilities may occur at other external components used in the project.The full cycle test is being performed right now but the upload problem has been fixed .

  1. Exclude the folder from project whenever you are building a project.
  2. Clean the project
  3. Build and deploy again

change this folder line to

string strFolder = @"D:\\TEST\\"; HttpContext.Current.Server.MapPath("~/test"); and place the file under same directory as Website

If Website cannot access d:\\test the file stays in temp folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM