Thursday 20 February 2014

Import Bulk Images from Client to server using asp.net with IONIC.Zip

 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);
       
        }
    }

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...