[上传下载] C# UpLoadFiles文件上传类 (转载)
2014-03-31 13:37 无抿屎的牛牛 阅读(742) 评论(0) 编辑 收藏 举报主要功能如下
/// <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, ""); } } }