File Content is erased after Uploading the File using ActiveXObject("MSComDlg.CommonDialog")

Jun 5 2007 8:46 AM
Hi all,

I am using ActiveXObject("MSComDlg.CommonDialog") for File Upload purpose. I am getting the FileName and I am using File Upload Control to Upload the File to the Server. When i upload the File the file content is erased and the file size will become 0 KB.

Here with I am attaching the Code snippet

Javascript Code:

<script type="text/javascript" language="javascript">

function Open() {

var oDLG ;

var FileName

var oDLG = new ActiveXObject("MSComDlg.CommonDialog");

oDLG.DialogTitle="Open";

oDLG.Filter="rpx files|*.rpx";

oDLG.MaxFileSize="255";

oDLG.Flags="oDLG.Flags" | "H1000"; //FileMustExist (OFN_FILEMUSTEXIST) ;

oDLG.ShowOpen();

if(oDLG.FileName!="")

{

FileName=oDLG.FileName;

document.form1.txtFileName.value=oDLG.FileName;

}

oDLG=null ;

}

</script>

ASP.NET Code:

I have a textbox and two buttons (Browse & Upload) & File upload Control

Protected Sub CmdUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmdUpload.Click

If txtFileName.Text <> "" Then
Dim fileExtension As String
Dim allowedExtensions As String() = {".rpx"}

fileExtension = System.IO.Path.GetExtension(txtFileName.Text).ToLower()
txtFName.Text = System.IO.Path.GetFileName(txtFileName.Text)

For i As Integer = 0 To allowedExtensions.Length - 1
 If fileExtension = allowedExtensions(i) Then
         fileOK = True
        End If
Next

If fileOK Then

FileUpload1.PostedFile.SaveAs(txtFName.Text)

END IF

End Sub

Is there any problem with the code or is there any workaround ?

Thanks & Regards,
Sreenivas Kaushik