コード例 #1
0
    public static bool SetCustomProperty(string filePath, Dictionary <string, object> dicKeyValue)
    {
        if (string.IsNullOrEmpty(filePath) || dicKeyValue == null || dicKeyValue.Count == 0)
        {
            return(false);
        }

        string extName = Path.GetExtension(filePath).ToLower();

        if (ListAllowExtFileNames.Contains(extName) == false)
        {
            return(false);
        }

        DocumentType type = getDocumentType(extName);

        if (type == DocumentType.Word2007 || type == DocumentType.Excel2007 || type == DocumentType.PowerPoint2007)
        {
            foreach (string key in dicKeyValue.Keys)
            {
                object value = dicKeyValue[key];

                if (value == null)
                {
                    value = "";
                }

                SetCustomPropertyByOffice2007(type, filePath, key, value, PropertyTypes.Text);
            }
        }
        else
        {
            SetCustomPropertyByCommonFile(filePath, dicKeyValue);
        }

        string WriteFilePropertyLogDir = AppDomain.CurrentDomain.BaseDirectory + ConfigurationSettings.AppSettings["WriteFilePropertyLogDir"];

        if (!string.IsNullOrEmpty(WriteFilePropertyLogDir))
        {
            object value = FilePropertyUtility.GetPropertyByDocumentType(type, filePath, "文档GUID");

            if (value != null)
            {
                if (!string.IsNullOrEmpty(WriteFilePropertyLogDir) && Directory.Exists(WriteFilePropertyLogDir) == false)
                {
                    Directory.CreateDirectory(WriteFilePropertyLogDir);
                }

                StreamWriter write = new StreamWriter(WriteFilePropertyLogDir + @"\\WriteFileWindowsPropertyLog.txt", true, Encoding.Default);
                write.WriteLine(DateTime.Now.ToString() + ",文件名称:" + Path.GetFileName(filePath) + ",扩展属性(文档GUID):" + value);
                write.Close();
                write.Dispose();
            }
        }

        return(true);
    }
コード例 #2
0
    static FilePropertyUtility()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //

        char[] chs = { '|' };

        string isEnabledWriteCustomPropertyStr = ConfigurationSettings.AppSettings["IsEnabledWriteCustomProperty"];

        if (!string.IsNullOrEmpty(isEnabledWriteCustomPropertyStr))
        {
            IsEnabledWriteCustomProperty = Convert.ToBoolean(isEnabledWriteCustomPropertyStr);
        }

        string AllowCustomPropertyExtFileNames = ConfigurationSettings.AppSettings["AllowCustomPropertyExtFileNames"];

        if (!string.IsNullOrEmpty(AllowCustomPropertyExtFileNames))
        {
            ListAllowExtFileNames.AddRange(AllowCustomPropertyExtFileNames.Split(chs, StringSplitOptions.RemoveEmptyEntries));
        }

        string CommonFileExtFileNames = ConfigurationSettings.AppSettings["CommonFileExtFileNames"];

        if (!string.IsNullOrEmpty(CommonFileExtFileNames))
        {
            ListCommonFile.AddRange(CommonFileExtFileNames.Split(chs, StringSplitOptions.RemoveEmptyEntries));
        }

        string OfficeFileExtFileNames = ConfigurationSettings.AppSettings["OfficeFileExtFileNames"];

        if (!string.IsNullOrEmpty(OfficeFileExtFileNames))
        {
            ListOfficeFile.AddRange(OfficeFileExtFileNames.Split(chs, StringSplitOptions.RemoveEmptyEntries));
        }
    }