Esempio n. 1
0
 private void UnzipFile(string zipFileName)
 {
     try
     {
         string fileName;
         fileName = "EQ" + dateTimePicker1.Value.Day.ToString("00") + dateTimePicker1.Value.Month.ToString("00") + dateTimePicker1.Value.Year.ToString().Replace("20", "") + ".CSV";;
         sbyte[] buf = new sbyte[1024];
         int     len;
         //filename = "EQ" + dateTimePicker1.Value.Day.ToString("00") + dateTimePicker1.Value.Month.ToString("00") + dateTimePicker1.Value.Year.ToString("00") + ".csv" ;
         //filename = filename.Replace("zip", "CSV");
         java.io.FileInputStream      fis = new java.io.FileInputStream(zipFileName);
         java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(fis);
         java.util.zip.ZipEntry       ze;
         while ((ze = zis.getNextEntry()) != null)
         {
             if (fileName == ze.getName())
             {
                 // File name format in zip file is:
                 // folder/subfolder/filename
                 // Let's check...
                 int index = fileName.LastIndexOf('/');
                 if (index > 1)
                 {
                     string        folder = fileName.Substring(0, index);
                     DirectoryInfo di     = new DirectoryInfo(folder);
                     // Create directory if not exists
                     if (!di.Exists)
                     {
                         di.Create();
                     }
                 }
                 java.io.FileOutputStream fos = new java.io.FileOutputStream(fileName);
                 while ((len = zis.read(buf)) >= 0)
                 {
                     fos.write(buf, 0, len);
                 }
                 fos.close();
             }
         }
         zis.close();
         fis.close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error" + ex.Message.ToString());
     }
     finally
     {
         // Close everything
     }
 }
        /// <summary>
        /// AUTHOR: Ashok Kolwal
        /// COMPANY: VITRANA
        /// Version: 1.0
        /// Description: The IDfSysObject.getContent() command lets you get the contents of a document as a ByteArrayInputStream
        /// Last Modified date: 11 Jul,2017
        /// </summary>
        /// <param name="sessionManager"></param>
        /// <param name="repositoryName"></param>
        /// <param name="objectIdString"></param>
        /// <returns></returns>
        public bool GetContent(IDfSessionManager sessionManager, String repositoryName, String objectIdString, String outputFolderPath)
        {
            IDfSession mySession = null;
            bool       result    = false;

            try
            {
                mySession = sessionManager.getSession(repositoryName);
                // Get the object ID based on the object ID string.
                IDfId idObj = mySession.getIdByQualification("dm_sysobject where r_object_id='" + objectIdString + "'");
                // Instantiate an object from the ID.
                IDfSysObject sysObj = (IDfSysObject)mySession.getObject(idObj);
                // This is file output path plus file name.
                string fileFullPath = string.Concat(outputFolderPath, "\\", sysObj.getObjectName(), ".", sysObj.getContentType());
                java.io.ByteArrayInputStream inputByteStrm = sysObj.getContent();
                java.io.InputStream          inputStrm     = inputByteStrm;
                java.io.OutputStream         outputStrm    = new java.io.FileOutputStream(fileFullPath);
                // Transfer bytes from in to out
                byte[] byteArry = new byte[30720];
                int    len      = 0;
                while ((len = inputStrm.read(byteArry)) > 0)
                {
                    outputStrm.write(byteArry, 0, len);
                }
                inputStrm.close();
                outputStrm.close();
                result = true;
                // Console.WriteLine("Document has been exported with Name: " + Path.GetFileName(fileFullPath));
            }
            // Handle any exceptions.
            catch (Exception ex)
            {
                // Console.WriteLine(ex.Message);
                throw new Exception("[GetContent] Error: " + ex.Message, ex);
            }
            // Always, always, release the session in the "finally" clause.
            finally
            {
                sessionManager.release(mySession);
            }

            return(result);
        }