1

Apps の導入により、ソリューションはなくなります。プログラムでサイト コレクションを作成する最良の方法は何ですか? 私はオンプレミスです。JavaScriptでできますか?js を使用してサブサイトを作成できますが、サイト コレクションはどうでしょうか?

サイト コレクションを作成するための C# コードをいくつか見つけましたが、どこから実行すればよいですか? アプリで?

4

1 に答える 1

2

イベント レシーバー (c#) を使用してプログラムでサイト コレクションを作成しました。Microsoft は、JavaScript を使用してサイト コレクションを作成できないことを確認しています。最初から最後まで完全なドキュメントが表示されないため、全体的なソリューションを共有すると思いました。

  1. 次の手順に従って、SP2013 http://msdn.microsoft.com/en-us/library/fp179923.aspxの適切な開発環境をセットアップしました
  2. 新しい VS2012 空の sharepoint 2013 プロジェクトを作成し、ファーム ソリューションを選択しました
  3. Web 参照を追加
    • サービス参照を右クリック
    • サービス参照を追加する
    • 詳細ボタン
    • Web 参照ボタンの追加
    • http://{SharePointServer}:{ポート}/_vti_adm/Admin.asmx
    • ファームアカウントでログイン
    • 参照に「SPAdminService」という名前を付けます
    • 参照ボタンを追加
  4. イベントレシーバーを追加

    • プロジェクトを右クリック
    • 追加
    • 新商品
    • イベントレシーバー
  5. eventreceiver.cs ファイルのコードは次のとおりです。

    using System;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.Workflow;
    
    
    namespace SharePointProject5.EventReceiver1
    {
    /// <summary>
    /// List Item Events
    /// </summary>
    public class EventReceiver1 : SPItemEventReceiver
    {
            /// <summary>
            /// An item is being added.
            /// </summary>
            public override void ItemAdding(SPItemEventProperties properties)
    {
        base.ItemAdding(properties);
        //create admin service reference
        SPAdminService.Admin admService = new SPAdminService.Admin();
        //grant proper admin credentials to admin service
        admService.Credentials = new System.Net.NetworkCredential("Farmaccount",         "Password", "Domain");            
        try
        {
            //specify new site collection path
            String SitePath = "http://twv101sp13/pm/new2013";
            //setup properties to create the site, see reference below for more info
            admService.CreateSite(SitePath, "new site", "description", 1033, "STS#1", "bluebunny\\sp13admin", "System Account", "cslee@bluebunny.com", "", "");                           
        }
        catch (System.Web.Services.Protocols.SoapException ex)
        {
            //I added this section so any errors would be logged in the server application log
            SPSecurity.RunWithElevatedPrivileges(
            delegate()
            {
                System.Diagnostics.EventLog.WriteEntry("Application", "Message:\n" + ex.MRessage + "\nDetail:\n" +
                    ex.Detail.InnerText +
                    "\nStackTrace:\n" + ex.StackTrace);
            });
        }
     }
    
    
     }
    }
    
  6. そのため、特定のリストに項目が追加されたときにのみこれを実行する必要があるため、Elements.xml ファイルを変更する必要があります。

  7. Elements.xml を開き、この行<Receivers ListTemplateId="101">を次のように置き換えます<Receivers ListUrl="http://{SharepointSite}/{targetListName}">- これは、サイト上のすべてのリストではなく、そのリストのみをターゲットにできるようにするためです。

  8. プロジェクトを右クリックしてデプロイします

  9. 新しいアイテムを作成して、新しいサイト コレクションを確認できるはずです。

私が経験した問題の 1 つは、サイトを数字で開始できないことです。

この記事の最後に、機能イベント レシーバーをデバッグする方法を示します。それがなければ、私は水の中で死んでいたでしょう: http://msdn.microsoft.com/en-us/library/ee231550.aspx

次の 3 つの記事が大いに役立ちました。

  1. http://msdn.microsoft.com/en-us/library/websvcadmin.admin.createsite.aspx

  2. http://onceinawhilescribble.blogspot.com/2013/05/creating-simple-event-receiver-in.html

  3. http://www.sharepointpals.com/post/How-to-create-a-custom-list-level-event-receiver-in-SharePoint-2013-and-SharePoint-2010

于 2013-07-18T18:53:39.547 に答える