在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.右键项目点属性; 2.点资源项,添加资源下拉框的添加现在文件,如下图:
3.直接上代码获取并复制到指定文件夹下: private void button1_Click(object sender, EventArgs e) { byte[] drawing1 = global::资源文件管理.Properties.Resources.Drawing1; byte[] gateway = global::资源文件管理.Properties.Resources.gateway; byte[] textgateway = global::资源文件管理.Properties.Resources.textgateway;//不需要后缀名 //string smno = global::资源文件管理.Properties.Resources.smno; List<byte[]> list = new List<byte[]>(); list.Add(drawing1); list.Add(gateway); list.Add(textgateway); DirectoryInfo dir = new DirectoryInfo(Application.StartupPath).Parent.Parent; string target = dir.FullName + "\\Resources";//资源文件路径 string[] files = Directory.GetFiles(target);//资源文件夹里的所有文件 for (int i = 0; i < files.Length; i++) { string str = Path.GetFileName(files[i]);//textgateway.exe CopyFileTo(@"c:\text\", str, list[i]); } this.Close(); } /// <summary> /// 复制文件 /// </summary> /// <param name="path"></param> /// <param name="fileName"></param> /// <param name="fileBuffer"></param> private void CopyFileTo(string path, string fileName, byte[] fileBuffer) { using (FileStream file = new FileStream(path + fileName, FileMode.Create)) { file.Write(fileBuffer, 0, fileBuffer.Length); } } /// <summary> /// 复制文件 /// </summary> /// <param name="path"></param> /// <param name="str"></param> public static void CopyFileTo(string path, string str) { using (StreamWriter sw = new StreamWriter(path)) { sw.Write(str); } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论