zoukankan      html  css  js  c++  java
  • silverlight中写Com组件 实现打开本地文件功能

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Diagnostics;
    
    
    namespace OpenFileCom
    {
        /// <summary>
        /// 事件接口
        /// </summary>
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        public interface IComEvents
        {
            /// <summary>
            /// 定义要暴露的事件
            /// </summary>
            void OnHelloBegin(object sender, EventArgs e);
        }
    
        public class HelloEvents : EventArgs
        { }
    
        /// <summary>
        /// 自定义定义委托
        /// </summary>
        public delegate void Comdel(object sender, EventArgs e);
    
        [ComVisible(true)]
        [ComSourceInterfaces(typeof(IComEvents))]
        public class IMDCOMTEST
        {
            public string Hello()
            {
                if (OnHelloBegin != null)
                    OnHelloBegin(this, new HelloEvents());
                return "asdasdasd";
            }
            public string OpenFile(string _path)
            {
    
                // var extensionName = Path.GetExtension(_path);
                try
                {
                    if (!File.Exists(_path))
                        throw new FileNotFoundException();
                    Process p = new Process();
                    p.StartInfo.FileName = "cmd.exe";           //設定程序名
                    p.StartInfo.Arguments = string.Format("/c \"{0}\"", _path);    //設定程式執行參數
                    p.StartInfo.UseShellExecute = false;        //關閉Shell的使用
                    p.StartInfo.RedirectStandardInput = true;   //重定向標準輸入
                    p.StartInfo.RedirectStandardOutput = true;  //重定向標準輸出
                    p.StartInfo.RedirectStandardError = true;   //重定向錯誤輸出
                    p.StartInfo.CreateNoWindow = true;          //設置不顯示窗口
                    return p.Start() ? "" : "打开失败";   //啟動                 
                }
                catch (Exception ex) { return ex.Message; }
            }
    
            /// <summary>
            /// 实现事件接口
            /// </summary>
            public event Comdel OnHelloBegin;
        }
    }
  • 相关阅读:
    HBase导入数据同时与Phoenix实现同步映射
    Hive导入数据到HBase,再与Phoenix映射同步
    CDH5.16.1离线集成Phoenix
    设计原则学习笔记
    Maven安装配置
    SpringBoot之Mybatis操作中使用Redis做缓存
    Linux服务器防火墙白名单设置
    Linux查看端口占用情况,并强制释放占用的端口
    shell脚本切割tomcat日志文件
    mysql读写分离
  • 原文地址:https://www.cnblogs.com/justin_wh/p/2741466.html
Copyright © 2011-2022 走看看