带有SharePoint参数的VB.Net命令行(控制台)程序 [英] VB.Net command line (console) program with parameters for SharePoint

查看:142
本文介绍了带有SharePoint参数的VB.Net命令行(控制台)程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试过看互联网,不是很成功。任何帮助将非常感谢。

 模块主要

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作为SPList = web.Lists(ListName)

Dim postInformation As String =<?xml version =1.0encoding =UTF-8?> ;方法>< 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 =标题> + prj.ToString +< / SetVar>< SetVar
Name =Overwrite> true< / SetVar>< / Method>

Dim processBatch As String = web.ProcessBatchData(postInformation)
'显示结果...
Console.WriteLine(processBatch)
Console.WriteLine Web部件页已成功添加)
Console.ReadLine()



结束子

结束模块



提前感谢!

解决方案

pre> public Sub Main(ByVal sArgs()As String)

如果sArgs.Length = 0那么'如果没有参数
Console.WriteLine (Hello World!< -no arguments passed->)'只输出Hello World
Else'我们有一些参数
Dim i As Integer = 0

i< sArgs.Length'每个参数
Console.WriteLine(Hello& sArgs(i)&!)'打印每个项目
i = i + 1'递增到下一个参数
End While

结束如果

结束子

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



很好的答案:Rajesh Sitaraman


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!

解决方案

 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

这篇关于带有SharePoint参数的VB.Net命令行(控制台)程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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