public void ImportImages(string path, string fname)
{
try
{
using (ZipFile zip1 = ZipFile.Read(path))
{
zip1.ExtractAll(Server.MapPath("~/UserImages"), ExtractExistingFileAction.OverwriteSilently);
}
string sdir = path.Substring(0, path.IndexOf('.'));
string destDirName = Server.MapPath("~/UserImages/");
DirectoryInfo dir = new DirectoryInfo(sdir);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
String ext = System.IO.Path.GetExtension(file.FullName);
if (ext.ToLower() == ".jpg" || ext.ToLower() == ".png" || ext.ToLower() == ".gif" || ext.ToLower() == ".bmb")
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, true);
}
}
//delete file
if (File.Exists(path))
{
File.Delete(path);
}
//delete directory
if (Directory.Exists(sdir))
{
Directory.Delete(sdir,true);
}
}
catch (Exception ex)
{
string mmsg = ex.Message;
showEXPMessages("(ImportImages) " + mmsg); showMessages(mmsg);
}
}
{
try
{
using (ZipFile zip1 = ZipFile.Read(path))
{
zip1.ExtractAll(Server.MapPath("~/UserImages"), ExtractExistingFileAction.OverwriteSilently);
}
string sdir = path.Substring(0, path.IndexOf('.'));
string destDirName = Server.MapPath("~/UserImages/");
DirectoryInfo dir = new DirectoryInfo(sdir);
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
String ext = System.IO.Path.GetExtension(file.FullName);
if (ext.ToLower() == ".jpg" || ext.ToLower() == ".png" || ext.ToLower() == ".gif" || ext.ToLower() == ".bmb")
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, true);
}
}
//delete file
if (File.Exists(path))
{
File.Delete(path);
}
//delete directory
if (Directory.Exists(sdir))
{
Directory.Delete(sdir,true);
}
}
catch (Exception ex)
{
string mmsg = ex.Message;
showEXPMessages("(ImportImages) " + mmsg); showMessages(mmsg);
}
}
No comments:
Post a Comment