hi all
why IE(8) show wrong FileName?
<pre lang="xml"><!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" runat="server" />
<hr />
<asp:Button ID="btnEncrypt" Text="Encrypt File" runat="server" OnClick="EncryptFile" />
<asp:Button ID="btnDecrypt" Text="Decrypt File" runat="server" OnClick="DecryptFile" />
<br />
<input type="submit" value="ersal" name="test" />
</div>
</form>
</body>
</html>
protected void EncryptFile(object sender, EventArgs e)
{
string fileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName);
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string input = Server.MapPath("~/Files/") + fileName + fileExtension;
string output = Server.MapPath("~/Files/") + fileName + "_enc" + fileExtension;
FileUpload1.SaveAs(input);
this.Encrypt(input, output);
Response.ContentType = FileUpload1.PostedFile.ContentType;
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(output));
Response.WriteFile(output);
Response.Flush();
File.Delete(input);
File.Delete(output);
Response.End();
}
private void Encrypt(string inputFilePath, string outputfilePath)
{
string EncryptionKey = "A";
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (FileStream fsOutput = new FileStream(outputfilePath, FileMode.Create))
{
using (CryptoStream cs = new CryptoStream(fsOutput, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
using (FileStream fsInput = new FileStream(inputFilePath, FileMode.Open))
{
int data;
while ((data = fsInput.ReadByte()) != -1)
{
cs.WriteByte((byte)data);
}
}
}
}
}
}
protected void DecryptFile(object sender, EventArgs e)
{
string fileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName);
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string input = Server.MapPath("~/Files/") + fileName + fileExtension;
string output = Server.MapPath("~/Files/") + fileName + "_dec" + fileExtension;
FileUpload1.SaveAs(input);
this.Decrypt(input, output);
Response.Clear();
Response.ContentType = FileUpload1.PostedFile.ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(output));
Response.WriteFile(output,false);
Response.Flush();
File.Delete(input);
File.Delete(output);
Response.End();
}
private void Decrypt(string inputFilePath, string outputfilePath)
{
string EncryptionKey = "A";
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (FileStream fsInput = new FileStream(inputFilePath, FileMode.Open))
{
using (CryptoStream cs = new CryptoStream(fsInput, encryptor.CreateDecryptor(), CryptoStreamMode.Read))
{
using (FileStream fsOutput = new FileStream(outputfilePath, FileMode.Create))
{
int data;
while ((data = cs.ReadByte()) != -1)
{
fsOutput.WriteByte((byte)data);
}
}
}
}
}
}