資源簡介
C#實(shí)現(xiàn)本地文件保存到另一臺(tái)電腦的代碼,另一外一臺(tái)電腦創(chuàng)建一個(gè)共享的文件夾everyone權(quán)限。

代碼片段和文件信息
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();
????????????//判斷本機(jī)文件是否存在
????????????if?(File.Exists(@“F:\\bianma.txt“))
????????????{
????????????????//存在則刪除掉
????????????????File.Delete(@“F:\\bianma.txt“);
????????????????//重新創(chuàng)建文件
????????????????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:目標(biāo)文件?????true:如有文件存在覆蓋掉??fales:不覆蓋
????????????????????File.Copy(origpath?newpath?true);
????????????????}
????????????}
????????????else
????????????{
????????????????//創(chuàng)建文件
????????????????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);
????????????????}
????????????}
????????}
????????//建立遠(yuǎn)程連接
????????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();
????????????????//遠(yuǎn)程連接地址和用戶名,密碼
????????????????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
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????10752??2014-12-13?11:12??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
?????文件??????26112??2014-12-13?11:12??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
?????文件??????11592??2014-12-13?11:16??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
?????文件????????490??2009-06-11?05:14??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
?????文件???????3623??2014-12-13?13:00??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
?????文件???????2770??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs
?????文件???????6008??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx
?????文件???????1331??2014-12-13?11:16??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
?????文件????????847??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
?????文件??????10752??2014-12-13?11:12??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe
?????文件????????180??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources
?????文件??????26112??2014-12-13?11:12??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb
?????文件????????180??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources
?????文件????????505??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs
?????文件???????1398??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs
?????文件???????2898??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs
?????文件???????5612??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx
?????文件???????1109??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs
?????文件????????249??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings
?????文件???????3759??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj
?????文件????????962??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1.sln
????..A..H.?????17408??2014-12-13?13:27??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1.suo
?????目錄??????????0??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\TempPE
?????目錄??????????0??2014-12-12?19:09??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug
?????目錄??????????0??2014-12-13?11:12??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug
?????目錄??????????0??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\bin
?????目錄??????????0??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\obj
?????目錄??????????0??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1\Properties
?????目錄??????????0??2014-12-13?13:00??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1\WindowsFormsApplication1
?????目錄??????????0??2014-12-12?18:58??案例??如何保存到另一臺(tái)電腦上\WindowsFormsApplication1
............此處省略4個(gè)文件信息
評論
共有 條評論