I have an upload button in which, when I upload file my file, must be uploaded in zip or compress form in specified path on server
I tried ===>
string strFileName = string.Empty;
string strserverPath = string.Empty;
if (UploadFiles.HasFile)
{
string abcPATH = tvFolders.SelectedValue.ToString();
string rootPath = tvFolders.SelectedNode.ToString();
string fname = Path.GetFileName(UploadFiles.PostedFile.FileName);
try
{
strserverPath = abcPATH + "\\" + fname;
//string strName = Path.GetFileName(UploadFiles.PostedFile.FileName);
Stream myStream = UploadFiles.PostedFile.InputStream;
byte[] myBuffer = new byte[myStream.Length + 1];
myStream.Read(myBuffer, 0, myBuffer.Length);
myStream.Close();
FileStream myCompressedFile = default(FileStream);
myCompressedFile = File.Create(Server.MapPath(Path.ChangeExtension("~/"+strserverPath, "zip")));
GZipStream myStreamZip = new GZipStream(myCompressedFile, CompressionMode.Compress);
myStreamZip.Write(myBuffer, 0, myBuffer.Length);
myStreamZip.Close();
//asp.net c#
//UploadFiles.PostedFile.SaveAs(Server.MapPath("~/" + strserverPath));
listofuploadedfiles.Text = "done";
}
catch (Exception ex)
{
Response.Write("Error" + ex.Message);
}
}
else
listofuploadedfiles.Text = "not done";
}