Passing custom data to SPWebProvisioningProvider class?

답변됨 Passing custom data to SPWebProvisioningProvider class?

  • 2012년 5월 8일 화요일 오후 10:08
     
     

    Hi All,

    How can I pass custom (dynamic) data to a custom provisioning provider? I cannot use ProvisionData because my data is not static which can be stored in an XML file. I need to pass data from a custom application page that provisions site using custom provisioning provider programmatically.

    Any ideas/pointers?

    Thank you!

모든 응답

  • 2012년 5월 8일 화요일 오후 10:35
    중재자
     
     

    Hi

    You should be able to do this by creating a class derived from SPWebProvisioningProvider and override the Provision method.  In Provision(),  you pass in your custom data using the SPWebProvisioningProperties parameter's  Data property. After having called  ApplyWebTemplate inside the Provision method   you can add your   custom logic from SPWebProvisioningProvider to activate features, create lists, sub sites etc. You probably have to do this with elevated privileges.


    Regards Bjoern
    Blog

  • 2012년 5월 9일 수요일 오후 6:24
     
     

    Can you please elaborate?

    I need to pass data to my custom provisioning provider which is derived from SPWebProvisioningProvider. In the provision method, I am activating a feature whose receiver expects to find a property in SPWeb object. So, somehow I need to set this property before activating the feature. Another important thing is, the property that I am trying to set should be passed in from an application page which invokes custom provisioning provider.

    Application Page ---> Custom Provisioning Provider ---> Feature Receiver

    So, there is a drop down list in the application page whose selected item's ID I need to pass to application page, then to provisioning provider and then to feature receiver.

    Any pointers?

  • 2012년 5월 9일 수요일 오후 7:19
    중재자
     
     
  • 2012년 5월 9일 수요일 오후 7:24
     
     
    Unfortunately, the link that you provided doesn't answer my question on how to pass custom data to provisioning provider from an application page. Am I missing something?
  • 2012년 5월 11일 금요일 오후 9:46
     
     
    anyone pointers?
  • 2012년 5월 12일 토요일 오전 3:11
     
     

    You should be able to set a querystring variable from your custom application page. Then possibly check in the provision method for HttpContext.Current.Request.QueryString for the ID.

    http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring.aspx


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    • 답변으로 표시됨 Shimin Huang 2012년 5월 18일 금요일 오전 6:04
    • 답변으로 표시 취소됨 diffident 2012년 5월 30일 수요일 오후 10:21
    •  
  • 2012년 5월 30일 수요일 오후 10:21
     
     

    You should be able to set a querystring variable from your custom application page. Then possibly check in the provision method for HttpContext.Current.Request.QueryString for the ID.

    http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring.aspx


    Blog | SharePoint Field Notes Dev Tool | ClassMaster


    Can you please let me know how I can set a querystring variable from application page? There is a drop down list in app. page that I would like to pass to custom provisioning provider. Do you mean that I need to set query string after the postback of app. page?
  • 2012년 5월 31일 목요일 오전 2:38
     
     

    Can you let me know how you are invoking the Custom Provisioning Provider from your application page. Usually the SPWeb is created first and the template is applied. So are you creating the SPWeb first in your application page?


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • 2012년 5월 31일 목요일 오후 1:57
     
      코드 있음

    THanks the quick reply, Steve. Here is my code snippet which provisions a new site by calling custom provisioning provider's site definition:

    SPWeb newSite = oWebsiteRoot.Webs.Add(clientAccountName, clientAccountName, "Client Account Site for " + clientAccountName, nLCID, "ClientAccountSiteDefinition.CustomProvisioningProvider#0", false, false);

    newSite.Title = this.ClientsDropDown.SelectedItem.Text; //store clientid in SPWeb property bag for later retrieval in the provisioning process newSite.SetProperty("clientid", this.ClientsDropDown.SelectedItem.Value); newSite.Update();

    As you can see above, I am trying to set a property in the new site but that property is not preserved or I am unable to find that property from custom provider.

    Please let me know if I am not clear.

    Thanks!

  • 2012년 5월 31일 목요일 오후 2:10
     
     

    You should be persisting and retrieving SPWeb properties using the AllProperties collection.  You can just add or update a property like this,

    newSite.AllProperties["clientid"] = this.ClientsDropDown.SelectedItem.Value;

    newSite.Update();

    This should be available from your provider by looking at newSite.AllProperties["clientid"]


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • 2012년 5월 31일 목요일 오후 2:12
     
     
    Thanks Steve. Let me give it a try! Will keep you posted.
  • 2012년 5월 31일 목요일 오후 2:16
     
     

    My other confusion:

    Line 1 is where provision method of custom provisioing provider is invoked and that is where I am accessing the property. But I am not setting the property until Line 3 by which time provision method would already have been executed? Is my assumption right? I am confused about the order of execution. Provision method is executed on line 1?

  • 2012년 5월 31일 목요일 오후 3:13
     
     
    The SharePoint UI provisions the web with a null argument for the template, then calls SPWeb.ApplyWebTemplate

    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • 2012년 5월 31일 목요일 오후 3:52
     
      코드 있음

    Still no luck Steve. This is how I am checking for property from Provision method:

                //retrieve current clientid from property bag
                if (props.Web.AllProperties.ContainsKey("clientid"))
                {
                    oWebsite.SetProperty("clientid", props.Web.AllProperties["clientid"].ToString());
                    oWebsite.Update();
                }
                else
                {
                    WriteLogEntry("there is no key");
                }

    In ULS logs, the log message "there is no key" is being logged. Am I missing something?

    This is how I am setting the property:

    newSite.AllProperties["clientid"] = this.ClientsDropDown.SelectedItem.Value;                
    newSite.Update();

    Thanks!

  • 2012년 5월 31일 목요일 오후 4:01
     
     
    Did you use SPWeb.ApplyWebTemplate and not send in the template argument when calling Web.Webs.Add?

    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • 2012년 5월 31일 목요일 오후 4:18
     
     

    No, I didn't.

    So, the sequence would be:

    1. add web with null argument.

    2. set property

    3. apply web template

    Does that look right to you?

  • 2012년 5월 31일 목요일 오후 4:26
     
     답변됨

    Yes, the ApplyWebTemplate method invokes the custom provider and web should have the property persisted by then.


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    • 답변으로 표시됨 diffident 2012년 5월 31일 목요일 오후 8:42
    •  
  • 2012년 5월 31일 목요일 오후 5:00
     
      코드 있음

    Steve - I tried the way you suggested but I get an error: A site template has already been applied to this site. Once a template has been applied, the site must be deleted and recreated in order to apply a different template

    Below is the code snippet:

    SPWeb newSite = oWebsiteRoot.Webs.Add(clientAccountName);
    newSite.Description = "Client Account Site for " + clientAccountName;
    newSite.Title = this.ClientsDropDown.SelectedItem.Text;
    //store clientid in SPWeb property bag for later retrieval in the provisioning process
    newSite.AllProperties["clientid"] = this.ClientsDropDown.SelectedItem.Value;
    newSite.ApplyWebTemplate("ClientAccountSiteDefinition.CustomProvisioningProvider#0");
    newSite.Update();

  • 2012년 5월 31일 목요일 오후 5:22
     
     

    Please use the code you used before except send in null for the template, Webs.Add(clientAccountName) appears to apply the default template.

    Also, call newSite.Update after calling newSite.AllProperties and before calling newSite.ApplyWebTemplate.


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • 2012년 5월 31일 목요일 오후 6:58
     
      코드 있음

    I am confused Steve. How can I send null for the template? I get compile-time error when I am using the below code:

    SPWeb newSite = oWebsiteRoot.Webs.Add(clientAccountName, clientAccountName, "Client Account Site for " + clientAccountName, nLCID, null, false, false);

    Pointers?
  • 2012년 5월 31일 목요일 오후 7:20
     
     
    Sorry, the SharePoint UI calls an internal Add method which can take a null. Instead of null try using string.empty.

    Blog | SharePoint Field Notes Dev Tool | ClassMaster

  • 2012년 5월 31일 목요일 오후 8:41
     
     
    That worked Steve! Thank you so much for being patient and guiding me in the process. Appreciate that.