File Upload does not work on Windows 7

  • Thread starter Thread starter Sheetal.K
  • Start date Start date
S

Sheetal.K

Guest
I have a file upload control with submit button in my app. which does not work in Windows 7 but works fine in Windows XP. There is not error message displayed. The file is pulled but does not upload.

Below is the code I have used.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TransFileAttachment.aspx.cs" Inherits="***Application.Transmission.Views.TransFileAttachment"

Title="TransFileAttachment" EnableEventValidation="false" ValidateRequest="false" %>


<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<script type="text/javascript" language="javascript" src="../scripts/FileAttachment.js"></script>

</head>

<body>

<form id="frmFileAttachment" runat="server">

<asp:FileUpload runat="server" ID="uploadAttachment"></asp:FileUpload>

</td>

</tr>

<tr>

<td>&nbsp;</td>

<td style="text-align:left;">

<obout:SuperButton

ID="btnUpload"

CausesValidation="true"

Runat="server"

Text="Upload"

SkinStyle="skype"

IsSubmit="true"

Validate="return OnUploadClick();"

PathPrefix="../App_Themes/Default/Button/">

</obout:SuperButton>


Script/FileAttachment.js

/*------------------------------------------------------------

//Click of btnUpload button, calls the following function

//Used to perform teh following validation and passess the control to the server

//Mandatory to upload a files

//Check the file type

//Check the file size

------------------------------------------------------------*/

function OnUploadClick()

{

var RtnVal = true;

var argForUpload = "Upload";


var CntlAttachment = GetCntluploadAttachment();//document.getElementById("uploadAttachment");

if(CntlAttachment.value == "")

{

ShowConfirmAlertMessage(CONST_VALIDATION, CONST_VALI_TITLE, "Please Select a file to Upload", '300', '100');

RtnVal = false;

}


if(RtnVal && !CheckSpecialChar(CntlAttachment.value))

{

ShowConfirmAlertMessage(CONST_VALIDATION, CONST_VALI_TITLE, "File name should not have any special characters", '300', '100');

RtnVal = false;

}


if(RtnVal && !CheckFileExtesion())

{

ShowConfirmAlertMessage(CONST_VALIDATION, CONST_VALI_TITLE, "File type is not allowed", '300', '100');

RtnVal = false;

}


if(RtnVal && !CheckFileSize())

{

ShowConfirmAlertMessage(CONST_VALIDATION, CONST_VALI_TITLE, "File size is more than the specified size of 10 Megabytes", '300', '100');

RtnVal = false;

}


return RtnVal;

}


.cs page code:


using System;

using System.Configuration;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using CommonUtilities;

using CommonUtilities.Entity;

using CommonUtilities.ErrorLogging;

using Microsoft.Practices.ObjectBuilder;




#region Event Handler

/// <summary>

/// To upload the selected file to the specified folder.

/// Store the file information in the table

/// Uses the dotnet fileupload control

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

protected void btnUpload_Click(object sender, EventArgs e)

{


string sStatus = string.Empty;

string sFullPath = string.Empty;

string sLocalFilePath = string.Empty;

string sFileInsSts = string.Empty;

string sFolerPath = string.Empty;

string folderWithLog = string.Empty;

string sFileName = string.Empty;

string LogNo = string.Empty;

string sFileAttchSts = Constants.NO;

//string msgs = "<script type=\"text/javascript\">alert('M1');</ScriptBehaviorDescriptor>";

//ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", msgs);

if (uploadAttachment.HasFile)

{

try

{


sFolerPath = FolderPath();

folderWithLog = FolderWithLogNo(sFolerPath, hidLogNo.Value);

sFileName = uploadAttachment.FileName;

LogNo = hidLogNo.Value;


if (!Directory.Exists(sFolerPath))

Directory.CreateDirectory(sFolerPath);


if (!Directory.Exists(folderWithLog))

Directory.CreateDirectory(folderWithLog);


sFullPath = FolderLogWithFileName(folderWithLog, sFileName);

lblFileNameDisp.Text = sFileName;

lblFilePathDisp.Text = uploadAttachment.PostedFile.FileName.ToString();

lblFileSizeDisp.Text = getFileSize(uploadAttachment.PostedFile.ContentLength);

lblContTypeDisp.Text = uploadAttachment.PostedFile.ContentType.ToString();


uploadAttachment.PostedFile.SaveAs(sFullPath);


if (!IsFileExists(hidLogNo.Value, sFileName))

{

sFileInsSts = TransInsDelFileDetails(hidLogNo.Value, sFileName, "I");

if (sFileInsSts == Constants.CONST_STATUS)

{

PopulateFiles(_transfileattachment);

sStatus = Constants.CONST_FILEULD_SUCC;

sFileAttchSts = Constants.YES;

}

else

{

sStatus = Constants.CONST_FILEULD_FAIL;

sFileAttchSts = Constants.NO;

}

}

else

{

sStatus = Constants.CONST_FILEULD_SUCC;

sFileAttchSts = Constants.YES;

}


dvFilesAttachment.Attributes.Add(Constants.CONST_STYLE, Constants.CONST_VISIBLE);


}

catch (Exception ex)

{

sStatus = Constants.CONST_FILEULD_FAIL;

sFileAttchSts = Constants.NO;

dvFilesAttachment.Attributes.Add(Constants.CONST_STYLE, Constants.CONST_VISIBLE);

string strErr = ex.Message.Replace("\r\n", " ");

ErrorSignal.FromContext(Context).Raise(ex);

ScriptManager.RegisterStartupScript(this, this.GetType(), "FolderPath", "fnShowErrorMessage('" + strErr + "');", true);

}


lblStatus.Text = sStatus;

hidFileAttached.Value = sFileAttchSts;

}

}

Continue reading...
 
Back
Top