为Sharepoint开发外接程序 - MVC Provider托管(Azure) [英] Developing Add-in for Sharepoint Online - MVC Provider hosted (Azure)

查看:55
本文介绍了为Sharepoint开发外接程序 - MVC Provider托管(Azure)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在尝试为Sharepoint在线开发提供商托管(Azure)MVC asp.net网络表单加载项。


1。你有没有人可以告诉我如何使用SP加载项创建一个列表


2。如何使用加载项输入和检索该列表中的数据



我已经完成了以下操作,但它没有在Sharepoint中创建列表


1。手动在SP开发人员站点中创建站点列,然后使用SP Online客户端浏览器获取每列的SchemaXML。 


2。然后使用我在Visual Studio中创建了sitecolumn< / g> 的SchemaXML,然后使用这些列在Visual Studio中创建内容类型,然后使用我在Visual Studio中创建列表的内容类型。 


3。创建模型和视图后,我使用以下代码访问列表 


4。然后我发布了加载项,但它没有在Sharepoint中创建列表。 


  &NBSP;公共类SharePointService

  &NBSP; {

  &NBSP; &NBSP; &NBSP;公共静态字符串GetUserName(SharePointContext spContext)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; string strUserName = null;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;用户spUser = null;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var clientContext = spContext.CreateUserClientContextForSPHost())

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(clientContext!= null)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; spUser = clientContext.Web.CurrentUser;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; clientContext.Load(spUser,user => user.Title);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; clientContext.ExecuteQuery();
$


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; strUserName = spUser.Title;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return strUserName;

  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; public static List< Models.Product> GetProducts(SharePointContext spContext,CamlQuery camlQuery)

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;列表与LT; Models.Product> products = new List< Models.Product>();



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; using(var clientContext = spContext.CreateUserClientContextForSPAppWeb())

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(clientContext!= null)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; List lstProducts = clientContext.Web.Lists.GetByTitle(" Products");



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ListItemCollection lstProductItems = lstProducts.GetItems(camlQuery);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; clientContext.Load(lstProductItems);



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; clientContext.ExecuteQuery();
$


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(lstProductItems!= null)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; foreach(lstProductItems中的var lstProductItem)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; products.Add(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新Models.Product <无线电通信/>
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP ;                 Title = lstProductItem [" Title"]。ToString(),

                   Description = lstProductItem [" ProductDescription"] .ToString(),

                   Price = lstProductItem [" Price"]。ToString()

                 });

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;退货产品;

  &NBSP; &NBSP; &NBSP; }




  &NBSP; }



非常感谢。




dn< g class =" gr_ gr_51 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace"数据-GR-ID =" 51" id =" 51"> weerasinghe< / g>






$

div class ="h2_lin">解决方案


您可以通过URL验证列表实例,如( https://domain-id.sharepoint.com/sites/lee/ SharePointAppLee / 列表/ LeeListData <跨度风格= "字体大小:介质"> / AllItems.aspx



有关创建新列表项的信息,请参考以下示例代码。


< pre class ="prettyprint"> //从ClientContext开始,构造函数需要一个运行SharePoint的
//服务器的URL。
ClientContext context = new ClientContext(" http:// SiteUrl");

//假设网站上有一个名为"公告"的列表。
List announcementsList = context.Web.Lists.GetByTitle(" Announcements");

//我们只是创建一个常规列表项,所以我们不需要
//设置任何属性。如果我们想创建一个新文件夹,对于
//示例,我们会必须将
// UnderlyingObjectType等属性设置为FileSystemObjectType.Folder。
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem [ " Title"] =" My New Item!" ;;
newItem [" Body"] =" Hello World!" ;;
newItem.Update();

context.ExecuteQuery();

您可以查看以下链接了解更多详情。


https://msdn.microsoft.com/en-us/library/office /fp179912.aspx的


最诚挚的问候,


Lee


Hi All,

I m trying to develop a provider hosted (Azure) MVC asp.net web form add-ins for Sharepoint online.

1. Could you please someone can tell me how to create a list using SP add-in

2. How to enter and retrieve data from that list using add-in

I have done following but it is not creating the list in Sharepoint

1. create the site columns in SP developer site manually and then use the SP Online client browser to get the SchemaXML for each column. 

2. then using those SchemaXMLs I have createdsitecolumn</g> in Visual Studio, then create a content type in Visual Studio using those columns, then using the content type I have created a list in Visual studio. 

3. After creating the Model and the view I have used the following code to access the list 

4. Then I publish the add-in but it doesn't create the list in Sharepoint. 

    public class SharePointService
    {
        public static string GetUserName(SharePointContext spContext)
        {
            string strUserName = null;

            User spUser = null;

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                if (clientContext != null)
                {
                    spUser = clientContext.Web.CurrentUser;

                    clientContext.Load(spUser, user => user.Title);

                    clientContext.ExecuteQuery();

                    strUserName = spUser.Title;
                }
            }

            return strUserName;
        }

        public static List<Models.Product> GetProducts(SharePointContext spContext, CamlQuery camlQuery)
        {
            List<Models.Product> products = new List<Models.Product>();

            using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
            {
                if (clientContext != null)
                {
                    List lstProducts = clientContext.Web.Lists.GetByTitle("Products");

                    ListItemCollection lstProductItems = lstProducts.GetItems(camlQuery);

                    clientContext.Load(lstProductItems);

                    clientContext.ExecuteQuery();

                    if (lstProductItems != null)
                    {
                        foreach (var lstProductItem in lstProductItems)
                        {
                            products.Add(
                                new Models.Product
                                {
                                    Title = lstProductItem["Title"].ToString(),
                                    Description = lstProductItem["ProductDescription"].ToString(),
                                    Price = lstProductItem["Price"].ToString()
                                });
                        }
                    }
                }
            }

            return products;
        }


    }

Thank you very much.


d.n <g class="gr_ gr_51 gr-alert gr_spell gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="51" id="51">weerasinghe</g>

解决方案

Hi,

You could validate your list instance by URL like(https://domain-id.sharepoint.com/sites/lee/SharePointAppLee/Lists/LeeListData/AllItems.aspx )

For creating new list item, here is sample code for your reference.

// Starting with ClientContext, the constructor requires a URL to the 
// server running SharePoint. 
ClientContext context = new ClientContext("http://SiteUrl"); 

// Assume that the web has a list named "Announcements". 
List announcementsList = context.Web.Lists.GetByTitle("Announcements"); 

// We are just creating a regular list item, so we don't need to 
// set any properties. If we wanted to create a new folder, for 
// example, we would have to set properties such as 
// UnderlyingObjectType to FileSystemObjectType.Folder. 
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); 
ListItem newItem = announcementsList.AddItem(itemCreateInfo); 
newItem["Title"] = "My New Item!"; 
newItem["Body"] = "Hello World!"; 
newItem.Update(); 

context.ExecuteQuery();  

You could check below link for more details.

https://msdn.microsoft.com/en-us/library/office/fp179912.aspx

Best Regards,

Lee


这篇关于为Sharepoint开发外接程序 - MVC Provider托管(Azure)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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