Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.Net command line (console) program with parameters for SharePoint

I would like to create a console program in VB.net that would allow parameters. What i would like to do is in the code below add parameters so the webpart page can be created from the Run menu. e.g. C:.......\MyProgram.exe "Design" --This would then create the Design webpart page.

I tried looking at the internet but was not very successfull. any help would be greatly appreciated.

      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

Thanks in advance!

like image 409
K-M Avatar asked Oct 29 '09 09:10

K-M


Video Answer


1 Answers

 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

Hope this helps, for accessing the command line arguments.

Great answer by: Rajesh Sitaraman

like image 192
K-M Avatar answered Sep 28 '22 17:09

K-M