![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C#
alvinan
Can't change the world change yourself
展开
-
c# post传文件
byte[] fileContentByte = new byte[10240]; // 文件内容二进制#region 将文件转成二进制FileStream fs = new FileStream("fastreport\\" + templateName, FileMode.Open, FileAccess.Read);fileContentByte = new byte[fs.Length]; // 二进制文件fs.Read(fileContentByte, 0, Convert.ToI原创 2021-08-11 17:13:36 · 1447 阅读 · 0 评论 -
c# 重启程序
重启1,有时会报错System.Windows.Forms.Application.Restart();重启2,稳定public void Restart(){//开启新的实例Process.Start(Application.ExecutablePath);//关闭当前实例Process.GetCurrentProcess().Kill();}Application.Exit();//退出当前项目,如果是子项目,则不会停止主项目System.Environm原创 2021-08-11 17:11:10 · 520 阅读 · 0 评论 -
c# 判断重复启动
Process[] processcollection = Process.GetProcessesByName("ZillionSoft.Workstation.Desktop");//获取指定的进程名if (processcollection.Length > 1) //如果可以获取到知道的进程名则说明已经启动{//MessageBox.Show("程序已启动2!");System.Environment.Exit(0);}...原创 2021-08-11 17:09:05 · 601 阅读 · 0 评论 -
c# 调用浏览器打开页面
using System;using System.Diagnostics;using System.IO;using System.Windows.Forms;using Microsoft.Win32;namespace WindowsFormsApplication1{public class BrowserHelper{/// <summary>/// 调用系统浏览器打开网页/// http://m.jb51.net/article/446原创 2021-08-11 17:07:33 · 2344 阅读 · 0 评论 -
c# 修改本地配置文件不删注释的方法
public static void SaveAppSettingsMethod2(string key, string value){//验证key value//To DoXmlDocument xml = new XmlDocument(); string configPath = Application.ExecutablePath + ".config";xml.Load(configPath);XmlNodeList nodeList = xml..原创 2021-03-04 14:02:05 · 426 阅读 · 1 评论 -
c# 关于配置文件
读当前项目配置文件string heightWeightFlag = ConfigurationSettings.AppSettings["heightWeightFlag"];读非当前项目配置文件string path = System.AppDomain.CurrentDomain.BaseDirectory;if (File.Exists(path + "../ZillionReport.exe.config"))//判断是否存在{ExeConfigurationFileMap原创 2021-03-04 13:59:24 · 194 阅读 · 1 评论 -
c#中对文件的简单操作
新建文件夹:if (!Directory.Exists(sPath))//判断是否存在{Directory.CreateDirectory(sPath);//新建文件夹}递归删除文件夹及内容if (Directory.Exists(dir)) //如果存在这个文件夹删除之{foreach(string d in Directory.GetFileSystemEntries(dir)){if(File.Exists(d))File.Delete(d); //直接删除原创 2021-03-04 13:53:51 · 200 阅读 · 1 评论 -
c#中计算字符串中子串出现的次数
static int SubstringCount(string str, string substring) { if (str.Contains(substring)) { string strReplaced = str.Replace(substring, ""); return (str.Length - strReplaced.Length) / substring.Length; } return 0; }原创 2021-03-04 13:52:10 · 569 阅读 · 1 评论 -
C# 注册dll的两种方式
普通注册string path = System.AppDomain.CurrentDomain.BaseDirectory ;System.Diagnostics.Process p = System.Diagnostics.Process.Start("regsvr32", path + "DicomObjects.ocx");管理员注册private bool RegisterDll(String dllPath){bool result = true;try{.原创 2021-03-04 13:49:44 · 1821 阅读 · 1 评论