• 大小: 43KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: C#  保存  

资源简介

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个文件信息

评论

共有 条评论