2009-10-29 67 views
5

我想在VB.net中創建一個允許參數的控制檯程序。我想要做的是在下面的代碼中添加參數,以便可以從運行菜單創建webpart頁面。例如C:....... \ MyProgram.exe「設計」 - 這將創建Design webpart頁面。具有SharePoint參數的VB.Net命令行(控制檯)程序

我試着在網上看,但並不是非常成功。任何幫助將不勝感激。

 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 

在此先感謝!

回答

15
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

相關問題