使用下列方法可以实现将json文件的内容读取出来,返回字符串。 publicstring Readjson(){string path = Path.GetFullPath("../../..") + "\\Json\\BS002.json";//JSON文件路径StreamReader sr = new StreamReader(path, Encoding.Default);string line;string jsonobj = "";while ((line = sr.ReadLine()) != null){jsonobj = jsonobj + line.ToString();}return jsonobj;} 原文:https://www.cnblogs.com/AduBlog/p/150440...
原文: 控件注册 - 利用资源文件将dll、ocx打包进exe文件(C#版) 很多时候自定义或者引用控件都需要注册才能使用,但是如何使要注册的dll或ocx打包到exe中,使用户下载以后看到的只是一个exe,点击直接运行呢?就像很多安全控件,如支付宝的aliedit.exe那样。 现在介绍一种使用资源文件,将dll、ocx打包进exe,点击直接注册的例子: 首先,新建一个工程RegisterFile。 新建文件夹Resource,里面添加需要注册的ocx...
遇到一个需求是在Unity3D做编辑器工具时需要把生成的AssetBundle包上传到资源服务器,资源服务器用的Linux。实现分为三部分:1,C#上传工具类;2,WinSCP脚本;3,传参调用使用上传功能。1,C#上传工具类using UnityEngine;
using System.Collections;
using System.IO;
using System;
using System.Diagnostics;public class UploadHelper
{ public static void callUploadProcess(string arguments)
{ string winS...
将C#的程序的一些用户数据写在一个文件中,并把程序设计为开机启动后,就会出现问题。找不到我的用户数据文件。File.Exists()返回的是false。但是如果手动打开程序又能成功的读取数据文件。 百度了一下也没有找到什么办法,就强制读取文件试一下,而不再用File.Exists()方法判断,结果给我抛出了一个异常:找不到文件:"C:\Windows\SysWOW64\Xxx"。 看了这个错误,估计是64位系统造成了,因为现在做的只是个小程序,没时间在...
[XmlRoot(ElementName = "product")]publicclass WMS_Query_ProductInfo{publicstring skuCode { get; set; }publicfloat normalQuantity { get; set; }publicfloat defectiveQuantity { get; set; }publicfloat averageWeight { get; set; }publicint? lineNo { get; set; }[XmlArray("batchs"), XmlArrayItem("batch")]public List<WMS_Query_Batch> batchs { get; set; }} publicclass WMS_Query_Batch{publicstring fixStatusC...
string file = ((fileNameIndex)index).ToString();if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/admin/upload/") + ((fileNameIndex)index).ToString()))Directory.Exists(HttpContext.Current.Server.MapPath("~/admin/upload/") + ((fileNameIndex)index).ToString());if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/admin/upload/") + file + "/" + DateTime.Now.ToString("yyyy")))Directory...
方法1:将图片复制到指定文件夹,在数据库中存储图片路径,通过读取路径来显示图片。string str;privatevoid toolStripButton1_Click(object sender, EventArgs e){if (openFileDialog1.ShowDialog() == DialogResult.OK){str = openFileDialog1.FileName;pictureBox1.Image = Image.FromFile(str);}}//打开文件并在PictureBox中显示图片privatevoid toolStripButton2_Click(object sender, EventArgs e){string filename = DateTi...
c# 操作txt文件
# 操作txt文件
c#创建文本privateconststring FILE_NAME = "ErroLog.txt";publicstaticvoid WriteFile(string str)...{StreamWriter sr; if (File.Exists(FILE_NAME)) //如果文件存在,则创建File.AppendText对象 ...{sr = File.AppendText(FILE_NAME);}else//如果文件不存在,则创建File.CreateText对象 ...{sr = File.CreateText(FILE_NAME);}sr.WriteLine(str);sr.Close();}C...
有这么一个情况,经常遇到一个项目的某个部分的功能与另一个项目的某个部分的代码是一样的,经常会遇到搬代码的情况,就觉得需要这么一个工具来自动搬就以C#为例,我发现虽然文件和目录都是可以copy的,但是呢,tfs或者说其他的源代码管理工具不一定就自动加上去了,所以最好是第一次搬动还是手工搬吧,有些整个项目都是新增的情况下。核心代码如下,供参考:这是copy主方法体,其中souce是源代码根目录,target:目标代码目录,ite...
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;namespace Flames.Utils.Net
{public class Http{/// <summary>/// 下载进度/// </summary>public event Action<int> ShowDownloadPercent;/// <summary>/// 一次下载量/// </summary>private int ByteSize = 1000000;/// <summary>/// 下载中的后缀,下载完成去掉/// </summary>private const string ...
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections.Specialized;using System.IO;using System.Runtime.InteropServices;using System.Windows.Forms;namespace test{ /// <summary> /// IniFiles的类 /// </summary> public class IniFiles { public string FileName; //INI文件名 //string path = System.IO.Path.Combine(Applica...
using System.Runtime.InteropServices;#region///<summary>/// 取exe文件绝对路径
///</summary>///<param name="hModule"></param>///<param name="lpFileName"></param>///<param name="nSize"></param>///<returns></returns>
[DllImport("kernel32")]
publicstaticexternint GetModuleFileName(IntPtr hModule, [Out] StringBuilder lpFileName,int nSize);
#endregion#region
IntPtr processHandle = IntPtr.Zero;
StringBui...
//表示清空 txtStreamWriter sw = new StreamWriter("D:\\1.txt"); string w = ""; sw.Write(w); sw.Close();//表示向txt写入文本StreamWriter sw = new StreamWriter("D:\\1.txt"); string w = "10"; sw.Write(w); sw.Close();//表示追加文本 StreamWriter sw =File.AppendText("D:\\1.txt"); string w = "2"; sw.Write(w); ...
文件操作: 检查 创建 读取 写入 修改 删除
目录操作: 检查 创建 读取 写入 修改 删除文件操作
创建文本文件 向文件写入文本
写入文本文件 向文件写入文本
读取文本文件 从文件读取文本向文件中追加文本 File.AppendText FileInfo.AppendText
重命名或移动文件 File.Move FileInfo.MoveTo
删除文件 File.Delete FileInfo.Delete
复制文件 File.Copy FileInfo.CopyTo
获取文件大小 FileInfo.Length
获取文件属性 File.GetAttributes
...
Prepare 本文将使用一个NuGet公开的组件技术来实现一个服务器端的文件管理引擎,提供了一些简单的API,来方便的实现文件引擎来对您自己的软件系统的文件进行管理。 在Visual Studio 中的NuGet管理器中可以下载安装,也可以直接在NuGet控制台输入下面的指令安装:Install-Package HslCommunication
NuGet安装教程 http://www.cnblogs.com/dathlin/p/7705014.html技术支持QQ群:592132877 (组件的版本更新细节也将第一时间在群里发...