如何使用asp.net在远程位置创建文件夹 [英] How to Create the Folder in Remote place using asp.net

查看:46
本文介绍了如何使用asp.net在远程位置创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ASp.net以编程方式在服务器中创建文件夹

我使用了以下代码:

How can i Create the Folder in my server programmtically using ASp.net

i have used the following Code:

public string GetComputerName(string clientIP)
        {
            try
            {
                var hostEntry = Dns.GetHostEntry(clientIP);
                return hostEntry.HostName;
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
        }


在上述方法中,请输入我服务器的IP地址,以获取计算机名称...


in the Above method ill give the IP Address of my Server in order to get the Machine name...

protected void Button1_Click(object sender, EventArgs e)
{

    lblIP.Text = GetComputerName(txtIP.Text);
    try
    {
        string myFolder = "MyFolderName";

        string UNCpath = "\\" + lblIP.Text.Trim() +\\My_Shared\\;

        string fullPath = UNCpath + myFolder;
        Directory.CreateDirectory(fullPath);//'Create folder

    }


使用以上我只能在本地计算机上创建文件夹".


Using Above i can create the Folder on my local machine only...

推荐答案

请确保您使用importing/using (depending on language) the System.IO namespace可以正常工作.然后尝试如下操作:

Make sure that you are importing/using (depending on language) the System.IO namespace for this to work. Then try like the following:

string pathToCreate = "~/UserFolders/" + "NAME HERE";
if(Directory.Exists(Server.MapPath(pathToCreate))
{
   //In here, start looping and modify the path to create to add a number
   //until you get the value needed
}

//Now you know it is ok, create it
Directory.CreateDirectory(Server.MapPath(pathToCreate));



请阅读以下文章以获取更多详细信息:
如何在ASP.NET中创建目录?
使用ASP.NET 2.0和VB .NET创建目录



Read following article for further detail:
How To Make Directory In ASP.NET?
Creating a directory using ASP.NET 2.0 and VB .NET


我找到了在具有一些具有完全访问权限的ShareFolder的远程服务器上创建文件夹的解决方案.
我用过

Directory.CreateDirectory(@"\\\\ Ur服务器IP地址\\服务器上的共享文件夹\\文件夹名称);

就是这样,它将在所需的服务器中为您创建一个文件夹.
因为它对于将文件远程存储到服务器非常有用... hehehehe .....
I have Found the Solution for Creating the folder on the Remote Server which has some ShareFolder with Full Access..

I have used

Directory.CreateDirectory(@"\\\\Ur Server IP Address\\Shared Folder on Server\\Name of the Folder );

That''s it will create a folder for you in the desired Server.....

as its useful for storing file to the server remotely...hehehehe.....


这篇关于如何使用asp.net在远程位置创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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