Пример #1
0
        /// <summary>
        /// Officeファイルのプロパティ取得
        /// </summary>
        /// <param name="list">対象のファイル</param>
        /// <returns>取得結果</returns>
        private bool ReadByDSO(ClsFilePropertyList list)
        {
            bool result = false;

            DSOFile.OleDocumentProperties docProperty = new DSOFile.OleDocumentProperties();
            DSOFile.SummaryProperties     summary;
            try
            {
                // ファイルを開く
                docProperty.Open(list.filePath, false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);
                // プロパティの取得
                summary = docProperty.SummaryProperties;

                if (summary.Keywords != null)
                {
                    string[] PropertyData = summary.Keywords.Split(';');
                    if (PropertyData[0] != "")
                    {
                        list.fileSecrecy = PropertyData[0].Trim(); // 機密区分を取得
                    }
                    else
                    {
                        list.fileSecrecy = "区分なし";
                    }
                    // プロパティが2つ以上ある場合文書分類を取得
                    if (PropertyData.Count() >= 2)
                    {
                        list.fileClassification = PropertyData[1].Trim();
                    }
                    // プロパティが3つ以上ある場合事業所を取得
                    if (PropertyData.Count() >= 3)
                    {
                        list.fileOfficeCode = PropertyData[2].Trim();
                    }

                    // 他事務所ファイル判定
                    if (Globals.ThisAddIn.clsCommonSettings.strOfficeCode != list.fileOfficeCode.Trim())
                    {
                        // 他事務所ファイルの場合、登録なし扱にする
                        list.fileSecrecy = "";
                    }
                }
                else
                {
                    list.fileSecrecy = "区分なし";
                }
                result = true;
            }
            finally
            {
                docProperty.Close();
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// PDFのプロパティ取得
        /// </summary>
        /// <param name="list">対象のファイル</param>
        /// <returns>取得結果</returns>
        private bool ReadByPDF(ClsFilePropertyList list)
        {
            bool result = false;

            PdfReader reader = new PdfReader(list.filePath);

            // プロパティ情報のリスト化
            List <string> name = new List <string>(reader.Info.Keys);
            List <string> val  = new List <string>(reader.Info.Values);

            reader.Close();

            int Property_Count = name.IndexOf("Keywords");

            if (name.Contains("Keywords") == false)
            {
                return(result);
            }

            string property = val[Property_Count];

            string[] propertyValue = property.Split(';');

            // propertyValue[0]が機密区分、[1]が文書分類、[2]が事業所?
            if (propertyValue.Count() != 0)
            {
                list.fileSecrecy = propertyValue[0];
            }
            if (propertyValue.Count() >= 2)
            {
                list.fileClassification = propertyValue[1];
            }
            if (propertyValue.Count() >= 3)
            {
                list.fileOfficeCode = propertyValue[2];
            }

            // 他事務所ファイル判定
            if (Globals.ThisAddIn.clsCommonSettings.strOfficeCode != list.fileOfficeCode.Trim())
            {
                // 他事務所ファイルの場合、登録なし扱にする
                list.fileSecrecy = "";
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// ファイルの機密区分を取得するメソッド
        /// </summary>
        /// <param name="list">対象ファイルのデータクラス</param>
        /// <returns>取得結果</returns>
        public bool FileCheck(ClsFilePropertyList list)
        {
            bool result = false;

            try
            {
                // ファイルが存在しない場合は処理を終了
                if (File.Exists(list.filePath) == false)
                {
                    return(result);
                }

                string fileType = NONE;

                var fileTypeDictionary = new Dictionary <string, string>()
                {
                    { ".pdf", PDF },
                    { ".xlsx", EXCEL }, { ".xlsm", EXCEL }, { ".xls", EXCEL },
                    { ".docx", WORD }, { ".doc", WORD },
                    { ".pptx", POWERPOINT }, { ".ppt", POWERPOINT }
                };
                if (fileTypeDictionary.TryGetValue(list.fileExtension, out fileType))
                {
                    fileType = fileTypeDictionary[list.fileExtension];
                }
                else
                {
                    fileType = NONE;
                }

                // 文書分類と機密区分を取得
                switch (fileType)
                {
                case PDF:
                    ReadByPDF(list);
                    break;

                case EXCEL:
                    if (ExtensionOpenXMLCheck(list.fileExtension) == true)
                    {
                        AccessToProperties          atp           = new AccessToProperties();
                        Dictionary <string, string> propertyTable = new Dictionary <string, string>();
                        string exception = "";
                        propertyTable = atp.ReadProperties(list, fileType, exception);
                    }
                    else
                    {
                        ReadByDSO(list);
                    }
                    break;

                case WORD:
                    if (ExtensionOpenXMLCheck(list.fileExtension) == true)
                    {
                        AccessToProperties          atp           = new AccessToProperties();
                        Dictionary <string, string> propertyTable = new Dictionary <string, string>();
                        string exception = "";
                        propertyTable = atp.ReadProperties(list, fileType, exception);
                    }
                    else
                    {
                        ReadByDSO(list);
                    }
                    break;

                case POWERPOINT:
                    if (ExtensionOpenXMLCheck(list.fileExtension) == true)
                    {
                        AccessToProperties          atp           = new AccessToProperties();
                        Dictionary <string, string> propertyTable = new Dictionary <string, string>();
                        string exception = "";
                        propertyTable = atp.ReadProperties(list, fileType, exception);
                    }
                    else
                    {
                        ReadByDSO(list);
                    }
                    break;

                case NONE:
                    list.fileSecrecy = SECRECY_NONE;
                    break;

                default:
                    list.fileSecrecy = "";
                    break;
                }
                list.rank = SetFileSecrecyRank(list.fileSecrecy);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), AddInsLibrary.Properties.Resources.msgError, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// プロパティを読み込みます
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="propertiesTable"></param>
        /// <returns>取得したプロパティ一覧</returns>
        public Dictionary <string, string> ReadProperties(ClsFilePropertyList list, string fileType, string str_exception)  // 20171011 修正(ファイル読込時のエラー理由を保存)
        {
            Dictionary <string, string> retTable = new Dictionary <string, string>();

            System.IO.FileInfo fi = new System.IO.FileInfo(list.filePath);
            if (fi.Length == 0)
            {
                // ファイルサイズがゼロの場合プロパティが存在しないのでエラー
                // 20171011 追加 (読取専用、ファイ存在しない以外のエラー)
                //error_reason = ListForm.LIST_VIEW_NA;
                return(retTable);
            }

            SpreadsheetDocument    excel = null;
            WordprocessingDocument word  = null;
            PresentationDocument   ppt   = null;

            CoreFilePropertiesPart coreFileProperties;

            // 20171011 修正(xlsxとdocxのみファイルを開いている状態でファイルアクセスするとエラーになる為の回避対応)
            try
            {
                // ファイルのプロパティ領域を開く
                switch (fileType)
                {
                case "Excel":     // エクセルの場合
                    excel = SpreadsheetDocument.Open(list.filePath, false);
                    coreFileProperties = excel.CoreFilePropertiesPart;
                    break;

                case "Word":     // ワードの場合
                    word = WordprocessingDocument.Open(list.filePath, false);
                    coreFileProperties = word.CoreFilePropertiesPart;
                    break;

                case "PowerPoint":     // パワポの場合
                    ppt = PresentationDocument.Open(list.filePath, false);
                    coreFileProperties = ppt.CoreFilePropertiesPart;
                    break;

                default:
                    // 異常なファイル
                    // 20171228 追加(エラー理由保存)
                    //error_reason = ListForm.LIST_VIEW_NA;
                    return(retTable);
                }
                NameTable           nt        = new NameTable();
                XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
                nsManager.AddNamespace(PropertiesKeyList.STR_TAG_CP, PropertiesSchemaList.CorePropertiesSchema);
                nsManager.AddNamespace(PropertiesKeyList.STR_TAG_DC, PropertiesSchemaList.DcPropertiesSchema);
                nsManager.AddNamespace(PropertiesKeyList.STR_TAG_DCTRMS, PropertiesSchemaList.DctermsPropertiesSchema);
                nsManager.AddNamespace(PropertiesKeyList.STR_TAG_DCMITYPE, PropertiesSchemaList.DcmitypePropertiesSchema);
                nsManager.AddNamespace(PropertiesKeyList.STR_TAG_XSI, PropertiesSchemaList.XsiPropertiesSchema);

                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(coreFileProperties.GetStream());

                // プロパティのキーリストを作成
                List <string> propertieslist = PropertiesKeyList.getPropertiesKeyList();

                // 全キーリストを見て存在するデータを取得
                foreach (string key in propertieslist)
                {
                    // 書き込み先のキーワードを指定
                    string searchString = string.Format(PropertiesKeyList.STR_CORE_PROPERTIES + "{0}", key);
                    // 書き込み先を検索
                    XmlNode xNode = xdoc.SelectSingleNode(searchString, nsManager);

                    if (xNode != null)
                    {
                        // 読み込む
                        retTable.Add(key, xNode.InnerText);
                    }
                }

                // ファイルのプロパティ領域を閉じる
                if (excel != null)
                {
                    excel.Close();
                }
                if (word != null)
                {
                    word.Close();
                }
                if (ppt != null)
                {
                    ppt.Close();
                }

                // プロパティ取得
                string[] propertyData = null;
                if (retTable.ContainsKey(PropertiesKeyList.STR_KEYWORDS) != false)
                {
                    propertyData = retTable[PropertiesKeyList.STR_KEYWORDS].Split(';');
                }

                if (propertyData != null)
                {
                    list.fileSecrecy = propertyData[0].TrimEnd();

                    // 機密区分が登録されているか判定
                    if (!string.IsNullOrEmpty(list.fileSecrecy))
                    {
                        // 登録あり
                        if (propertyData.Count() >= 1)
                        {
                            list.fileClassification = propertyData[1].TrimEnd();
                        }
                        if (propertyData.Count() >= 2)
                        {
                            list.fileOfficeCode = propertyData[2].TrimEnd();
                        }

                        // 他事務所ファイル判定
                        if (Globals.ThisAddIn.clsCommonSettings.strOfficeCode != list.fileOfficeCode.Trim())
                        {
                            // 他事務所ファイルの場合、登録なし扱にする
                            list.fileSecrecy = "";
                        }
                    }
                }
                else
                {
                    list.fileSecrecy = "Notting";
                }
            }
#if false
            #region HyperLink修復

            // ■ ADD TSE Kitada
            // HyperLinkが破損している場合に、そのリンクを書き直して正常にOPEN出来るようにする。
            // 但し、ドキュメントの中身を直接書き換える処理のため、見送る。
            catch (OpenXmlPackageException ope)
            {
                if (ope.ToString().Contains("Invalid Hyperlink"))
                {
                    // HyperLinkの破損が原因なので、内部のリンクを修正する
                    using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                    {
                        UriFixer.FixInvalidUri(fs, brokenUri => FixUri(brokenUri));
                    }

                    if (count >= 1)
                    {
                        // 2回実行してダメだったので終了
                        error_reason = ListForm.LIST_VIEW_NA;
                    }
                    else
                    {
                        // もう一度トライ
                        retTable = ReadProperties(filePath, filetype, ref error_reason, ref str_exception, 1);
                    }
                }

                if (excel != null)
                {
                    excel.Close();
                }
                if (word != null)
                {
                    word.Close();
                }
                if (ppt != null)
                {
                    ppt.Close();
                }
            }
            #endregion
#endif
            catch (Exception e)
            {
                str_exception += "file : " + list.filePath + "\r\n\r\n";
                str_exception += "error : " + e.ToString();
                // xlsxとdocxのみファイルを開いている状態でファイルアクセスした場合
                // ファイルが開かれている場合のエラー
                //error_reason = ListForm.LIST_VIEW_NA;

                if (excel != null)
                {
                    excel.Close();
                }
                if (word != null)
                {
                    word.Close();
                }
                if (ppt != null)
                {
                    ppt.Close();
                }

                return(retTable);
            }
            return(retTable);
        }