开发者

Creating a Directory on a remote machine using VB.NET

How can I create a directory on a remote server using .NET? Both servers are running Windows Server 2003. I have looked at the system.IO.directory class, and FtpWebRequest, both of which don't seem to do what I need.

If there isn't an existing method for this, I should be able to form a VPN tunnel, map the drive, and use directory.copy, right?

Update: Decided to take Rockinthesixstring's advice and create a web service on the server in which I need to create the directories. I built the following ASMX file, compiled it in visual studio, and was able to successfully invoke it from the browser page that is "automagically" generated from the ASMX file

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

    <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://ttanet.com/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class Service1
        Inherits System.Web.Services.WebService
        <WebMethod()> _

        'Here is where we invoke our exposed method'
        Public Sub makeDir(ByVal dirName As String)
            System.IO.Directory.CreateDirectory("C:/TransferTest/" & dirName)
        End Sub

    End Class

Excellent suggestion -Thanks Rockin...

The second half of my question is the best way to invoke it. I need to call it from a VB.NET app. I am trying to invoke it from a browser, like开发者_如何学编程:

http://localhost:60870/MakeDirectory.asmx/makeDir?dirName=testingFromURL

But it yields:

Exception Details: System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/makeDir'.

I was planning on looping through and sending WebRequestFactory.Create(urlForGetRequest) through an iteration. Is something wrong with the way my URL is structured, Is there a better way?


I would recommend creating a web service on the machine that is to have the directory created. Then call the web service from the machine that is doing the creating. The web service can use the System.IO.Directory.CreateDirectory method.

An alternative method would be to create the directory directly using a UNC Path. (requires a folder share across the network)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜