• [上传下载] C# UpLoadFiles文件上传类 (转载)


    点击下载 UpLoadFiles.zip

    主要功能如下

            /// <summary>
            /// 上传文件
            /// </summary>
            /// <param name="filePath">保存文件地址</param>
            /// <param name="maxSize">文件最大大小</param>
            /// <param name="fileType">文件后缀类型</param>
            /// <param name="TargetFile">控件名</param>
            /// <param name="saveFileName">保存后的文件名和地址</param>
            /// <param name="fileSize">文件大小</param>
            /// <returns></returns>

    看下面代码吧

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    using System.Diagnostics;
     
    namespace AutoApk
    {
        /// <summary>
        /// Cmd 的摘要说明。
        /// </summary>
        public class Cmd
        {
            private Process proc = null;
            /// <summary>
            /// 构造方法
            /// </summary>
            public Cmd()
            {
                proc = new Process();
            }
            /// <summary>
            /// 执行CMD语句
            /// </summary>
            /// <param name="cmd">要执行的CMD命令</param>
            public string RunCmd(string cmd)
            {
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.FileName = "cmd.exe";
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.Start();
                proc.StandardInput.WriteLine(cmd.Substring(0, cmd.IndexOf(":")) + ":");
                cmd = "cd " + cmd;
                foreach (var item in cmd.Split(','))
                {
                    proc.StandardInput.WriteLine(item);
                }
                proc.StandardInput.WriteLine("exit");
                string outStr = proc.StandardOutput.ReadToEnd();
                proc.Close();
                return outStr;
            }
            /// <summary>
            /// 打开软件并执行命令
            /// </summary>
            /// <param name="programName">软件路径加名称(.exe文件)</param>
            /// <param name="cmd">要执行的命令</param>
            public void RunProgram(string programName, string cmd)
            {
                Process proc = new Process();
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.FileName = programName;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.Start();
                if (cmd.Length != 0)
                {
                    proc.StandardInput.WriteLine(cmd);
                }
                proc.Close();
            }
            /// <summary>
            /// 打开软件
            /// </summary>
            /// <param name="programName">软件路径加名称(.exe文件)</param>
            public void RunProgram(string programName)
            {
                this.RunProgram(programName, "");
            }
        }
    }
  • 相关阅读:
    DNS 截持模拟及环境搭建
    Ant、Gradle、Python三种打包方式的介绍
    oc/c/c++混编老文,写的很好,mark
    好文!关于iOS下的正则表达式实战案例
    Java设计模式——享元模式
    Java 消息机制之回调详解
    windows版爬取csdn
    14.6.2 Configuring InnoDB for Read-Only Operation
    dump iot表
    heap表按字符串和数值型排序规则
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3635545.html
Copyright © 2020-2023  润新知