复制文件名

2015-11-12 12:22:21  访问(1626) 赞(0) 踩(0)


        /// <summary>
        /// 获得当前文档的文件名
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public string GetDocumentFullName(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
            {
                throw new Exception
                   (
                       "方法:"
                       + MethodBase.GetCurrentMethod().ReflectedType.FullName
                       + " "
                       + MethodBase.GetCurrentMethod().ToString()
                       + " 发生异常:"
                       + "DTE2 _applicationObject"
                       + "值为null。"
                   );
            }


            Document doc = _applicationObject.ActiveDocument;

            if (doc == null)
            {

                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:"
                        + "Document doc = _applicationObject.ActiveDocument"
                        + "值为null。"
                    );
            }

            return doc.FullName;

        }


        /// <summary>
        /// 复制文件名
        /// </summary>
        /// <param name="_applicationObject"></param>
        public void CopyFileName(DTE2 _applicationObject)
        {
            string fileName = GetDocumentFullName(_applicationObject);

            fileName = Path.GetFileName(fileName);
 
            Clipboard.SetDataObject(fileName);
        }


标签:复制文件名 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)