如何使用asp.net c#通过网络将文件从一个系统移动到另一个系统? [英] how to move the file from one system to another system over a network using asp.net c#?

查看:72
本文介绍了如何使用asp.net c#通过网络将文件从一个系统移动到另一个系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

告诉我使用asp.net c#通过网络将文件从一个系统移动到另一个系统的步骤。我开发使用asp.net c#windows应用程序,它在localdisk C:drive到d:drive的本地文件传输中工作正常。但是,如果我把ipaddress设置为\\192.168.10.37\c $ \prabu1,它将不会将文件移动到该目的地[192.168.10.37]。我附上了代码供您参考。通过适当的解决方案给我一个有价值的反馈。



代码:

**************

  private   void  Form1_Load( object  sender,EventArgs e)
{
string source_directory = @ c:\ datas;
string destination_directory = @ \\\ \\192.168.10.37\d $ \prabu1\" ;

DirectoryInfo sourceinfo = new DirectoryInfo(source_directory);
DirectoryInfo destinationinfo = new DirectoryInfo(destination_directory);

if (sourceinfo.Exists)
{
string s1 = sourceinfo.FullName;
string d1 = destinationinfo.FullName;
if (Directory.GetFiles(s1).Length > 0 && Directory.GetDirectories(s1).Length == 0
{
if (destinationinfo.Exists)
{
string s = sourceinfo.FullName;

foreach var filenames in Directory.GetFiles(s1))
{
// File.Move (str,Path.Combine(dir,Path.GetFileName(str)));

string source_location = filenames;

string prabu = Path.GetFileName(source_location);

string myFile = source_location;
string fileToCopy = destination_directory + \\\ \\ + prabu;

if (File.Exists(fileToCopy))
{
File.Delete(fileToCopy);
}
File.Move(myFile,fileToCopy);
}
}
}
}
其他
{
// this.Close();
notifyIcon1.BalloonTipText = 该位置不存在此类目录;
notifyIcon1.Visible = true ;
notifyIcon1.ShowBalloonTip( 300 通知图标 该位置中不存在此类目录,ToolTipIcon.Error);
// MessageBox.Show(该位置不存在此类目录,找不到文件夹, MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}

解决方案

\prabu1 ,它不会将文件移动到该目的地[192.168.10.37]。我附上了代码供您参考。给我一个有价值的反馈,并提供适当的解决方案。



代码:

**************

  private   void  Form1_Load( object  sender,EventArgs e)
{
string source_directory = @ c:\ datas ;
string destination_directory = @ \\1 92.168.10.37\d

\prabu1\" ;

DirectoryInfo sourceinfo = new DirectoryInfo(source_directory);
DirectoryInfo destinationinfo = new DirectoryInfo(destination_directory);

if (sourceinfo.Exists)
{
string s1 = sourceinfo.FullName;
string d1 = destinationinfo.FullName;
if (Directory.GetFiles(s1).Length > 0 && Directory.GetDirectories(s1).Length == 0
{
if (destinationinfo.Exists)
{
string s = sourceinfo.FullName;

foreach var filenames in Directory.GetFiles(s1))
{
// File.Move (str,Path.Combine(dir,Path.GetFileName(str)));

string source_location = filenames;

string prabu = Path.GetFileName(source_location);

string myFile = source_location;
string fileToCopy = destination_directory + \\\ \\ + prabu;

if (File.Exists(fileToCopy))
{
File.Delete(fileToCopy);
}
File.Move(myFile,fileToCopy);
}
}
}
}
其他
{
// this.Close();
notifyIcon1.BalloonTipText = 该位置不存在此类目录;
notifyIcon1.Visible = true ;
notifyIcon1.ShowBalloonTip( 300 通知图标 该位置中不存在此类目录,ToolTipIcon.Error);
// MessageBox.Show(该位置不存在此类目录,找不到文件夹, MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}


请检查我之前对另一个CPian的回答。这同样适用于您的答案。您需要首先模拟通过网络传输文件。请在此处查看我的答案:如何通过LAN连接存储图像或图片另一台服务器 [ ^ ]



祝你好运,

OI


Hi sir,
Tell me the steps to move the file from one system to another system over a network using asp.net c#. I developed using asp.net c# windows application, its working fine in local file transfer from localdisk C: drive to d: drive. But if i put ipaddress like "\\192.168.10.37\c$\prabu1", it will not move the file to that destination [192.168.10.37]. I attached the code for your reference. Give me a valuable feedback with the proper solution.

Code:
**************

private void Form1_Load(object sender, EventArgs e)
{
    string source_directory = @"c:\datas";
    string destination_directory = @"\\192.168.10.37\d$\prabu1";
    
    DirectoryInfo sourceinfo = new DirectoryInfo(source_directory);
    DirectoryInfo destinationinfo = new DirectoryInfo(destination_directory);
    
    if (sourceinfo.Exists)
    {
        string s1 = sourceinfo.FullName;
        string d1 = destinationinfo.FullName;
        if (Directory.GetFiles(s1).Length > 0 && Directory.GetDirectories(s1).Length == 0)
        {
            if (destinationinfo.Exists)
            {
                string s = sourceinfo.FullName;
                
                foreach (var filenames in Directory.GetFiles(s1))
                {
                    //File.Move(str, Path.Combine(dir, Path.GetFileName(str)));
                    
                    string source_location = filenames;
                    
                    string prabu = Path.GetFileName(source_location);
                    
                    string myFile = source_location;
                    string fileToCopy = destination_directory+"\\"+prabu;
                    
                    if (File.Exists(fileToCopy))
                    {
                    File.Delete(fileToCopy);
                    }
                    File.Move(myFile, fileToCopy);
                }
            }
        }
    }
    else
    {
        //this.Close();
        notifyIcon1.BalloonTipText = "No such directory exists in that location";
        notifyIcon1.Visible = true;
        notifyIcon1.ShowBalloonTip(300, "Notify Icon", "No such directory exists in that location", ToolTipIcon.Error);
        //MessageBox.Show("No such directory exists in that location", "Folder not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

解决方案

\prabu1", it will not move the file to that destination [192.168.10.37]. I attached the code for your reference. Give me a valuable feedback with the proper solution.

Code:
**************

private void Form1_Load(object sender, EventArgs e)
{
    string source_directory = @"c:\datas";
    string destination_directory = @"\\192.168.10.37\d


\prabu1"; DirectoryInfo sourceinfo = new DirectoryInfo(source_directory); DirectoryInfo destinationinfo = new DirectoryInfo(destination_directory); if (sourceinfo.Exists) { string s1 = sourceinfo.FullName; string d1 = destinationinfo.FullName; if (Directory.GetFiles(s1).Length > 0 && Directory.GetDirectories(s1).Length == 0) { if (destinationinfo.Exists) { string s = sourceinfo.FullName; foreach (var filenames in Directory.GetFiles(s1)) { //File.Move(str, Path.Combine(dir, Path.GetFileName(str))); string source_location = filenames; string prabu = Path.GetFileName(source_location); string myFile = source_location; string fileToCopy = destination_directory+"\\"+prabu; if (File.Exists(fileToCopy)) { File.Delete(fileToCopy); } File.Move(myFile, fileToCopy); } } } } else { //this.Close(); notifyIcon1.BalloonTipText = "No such directory exists in that location"; notifyIcon1.Visible = true; notifyIcon1.ShowBalloonTip(300, "Notify Icon", "No such directory exists in that location", ToolTipIcon.Error); //MessageBox.Show("No such directory exists in that location", "Folder not found", MessageBoxButtons.OK, MessageBoxIcon.Error); } }


Please check my previous answer to another CPian. The same applies to your answer as well. You need to impersonate first to transfer files over network. Please check my answer here:how to store image or picture another server through LAN connection[^]

Good luck,
OI


这篇关于如何使用asp.net c#通过网络将文件从一个系统移动到另一个系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆