资源简介
C#实现本地文件保存到另一台电脑的代码,另一外一台电脑创建一个共享的文件夹everyone权限。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//按钮事件
private void button1_Click(object sender EventArgs e)
{
string zfcstr = textBox1.Text.Trim();
//判断本机文件是否存在
if (File.Exists(@“F:\\bianma.txt“))
{
//存在则删除掉
File.Delete(@“F:\\bianma.txt“);
//重新创建文件
StreamWriter sw = File.AppendText(@“F:\\bianma.txt“);
sw.Write(zfcstr);
sw.Flush();
sw.Close();
if (connectState())
{
string newpath = System.IO.Path.GetFullPath(@“////192.168.82.99//e$//共享//bianma.txt“);
string origpath = System.IO.Path.GetFullPath(@“F:\\bianma.txt“);
//origpath:源文件 newpath:目标文件 true:如有文件存在覆盖掉 fales:不覆盖
File.Copy(origpath newpath true);
}
}
else
{
//创建文件
StreamWriter sw = File.AppendText(@“F:\\bianma.txt“);
sw.Write(zfcstr);
sw.Flush();
sw.Close();
if (connectState())
{
string newpath = System.IO.Path.GetFullPath(@“////192.168.82.99//e$//共享//bianma.txt“);
string origpath = System.IO.Path.GetFullPath(@“F:\\bianma.txt“);
File.Copy(origpath newpath true);
}
}
}
//建立远程连接
public static bool connectState()
{
bool Flag = false;
Process proc = new Process();
try
{
proc.StartInfo.FileName = “cmd.exe“;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
//远程连接地址和用户名,密码
string dosLine = @“net use \\192.168.82.99\e$\共享 123456 /user:192.168.82.99\administrator“;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine(“exit“);
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
string errormsg = proc.StandardError.ReadToEnd();
proc.StandardError.Close();
if (string.IsNullOrEmpt
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10752 2014-12-13 11:12 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
文件 26112 2014-12-13 11:12 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
文件 11592 2014-12-13 11:16 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
文件 490 2009-06-11 05:14 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
文件 3623 2014-12-13 13:00 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
文件 2770 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
文件 6008 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
文件 1331 2014-12-13 11:16 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
文件 847 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
文件 10752 2014-12-13 11:12 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe
文件 180 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources
文件 26112 2014-12-13 11:12 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb
文件 180 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources
文件 505 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
文件 1398 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
文件 2898 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
文件 5612 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
文件 1109 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
文件 249 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
文件 3759 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
文件 962 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1.sln
..A..H. 17408 2014-12-13 13:27 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1.suo
目录 0 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\TempPE
目录 0 2014-12-12 19:09 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug
目录 0 2014-12-13 11:12 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug
目录 0 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\bin
目录 0 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\obj
目录 0 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1\Properties
目录 0 2014-12-13 13:00 案例 如何保存到另一台电脑上\WindowsFormsApplication1\WindowsFormsApplication1
目录 0 2014-12-12 18:58 案例 如何保存到另一台电脑上\WindowsFormsApplication1
............此处省略4个文件信息
- 上一篇:wince下的C#读取xm
l文件 - 下一篇:c#调用EXCEL宏及操作类
相关资源
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
评论
共有 条评论