带有SharePoint参数的VB.Net命令行(控制台)程序

时间:2009-10-29 09:51:39

标签: vb.net sharepoint console

我想在VB.net中创建一个允许参数的控制台程序。我想要做的是在下面的代码中添加参数,以便可以从“运行”菜单创建webpart页面。例如C:....... \ MyProgram.exe“设计” - 然后创建Design webpart页面。

我试过看互联网,但不太成功。任何帮助将不胜感激。

      Module Main

                Public Sub Main(ByVal args As String())
          Dim prj As String

                    Dim site As New SPSite("http://site/")
                    Dim web As SPWeb = site.AllWebs(0)

                    Dim list As SPList = web.Lists("ListName")

Dim postInformation As String = "<?xml version=""1.0"" encoding=""UTF-8""?><Method><SetList Scope=""Request"">" + list.ID.ToString + "</SetList><SetVar 
    Name=""ID"">New</SetVar><SetVar Name=""Cmd"">NewWebPage</SetVar><SetVar 
    Name=""Type"">WebPartPage</SetVar><SetVar Name=""WebPartPageTemplate"">2</SetVar><SetVar 
    Name=""Title"">" + prj.ToString + "</SetVar><SetVar 
    Name=""Overwrite"">true</SetVar></Method>"

                    Dim processBatch As String = web.ProcessBatchData(postInformation)
                 'Display the results...
                Console.WriteLine(processBatch)
                    Console.WriteLine("New Web part page added successfully")
                    Console.ReadLine()



                End Sub

        End Module

提前致谢!

1 个答案:

答案 0 :(得分:16)

 Public Sub Main(ByVal sArgs() As String)

    If sArgs.Length = 0 Then                'If there are no arguments
        Console.WriteLine("Hello World! <-no arguments passed->") 'Just output Hello World
    Else                                    'We have some arguments 
        Dim i As Integer = 0

        While i < sArgs.Length             'So with each argument
            Console.WriteLine("Hello " & sArgs(i) & "!") 'Print out each item
            i = i + 1                       'Increment to the next argument
        End While

    End If

End Sub

希望这有助于访问命令行参数。

回答:Rajesh Sitaraman