SPWeb.ApplyWebTemplate() method - delay issue - sharepoint

I have a custom site definition and in the provisioning handler I am using SPWeb.ApplyWebTemplate("My site defintion name") to apply the site definition. It works fine but i have observed that there is some delay in applying the web template.
What i did is that in the onet of my site defintion i have set the masterurl attribute to /_catalogs/masterpage/MyMaster.master. Now if i create a site under sites folder using this site definition, the sites gest create successfully but on browsing it throws the error as "resource cannot be found". I did some investigation and came to know that the master url should be server relative and not the site relative. So in the provisioning code after applying the template i write the code to update the master URL by prepending Site's server relative URL to it.
Web.MasterUrl = Site.ServerRelativeUrl + Web.MasterUrl;
But when i browse the site it did not work and i got the same error. I debugged the code and found that the even after applying the template the master URL is set to default.master. I waited there on that statement in the debug mode and found that after some time (some secs) the master URL changed to the URL which i set in the onet i.e MyMaster.master.
So looks like ApplyWebTemplate() is an asynchronous method. How can I be assure that the applying web template process is finished.
Thanks.

You could try getting a new spWeb object for the site after the call and check the Template property.

Related

How to create single page application in liferay 7?

Can anyone share some detailed info on how to create a Single Page Application (SPA) in Liferay 7 using SennaJS.
I could't found any documentation on How to create SPA in Liferay 7.
It comes by default, except if you unset the following property:
javascript.single.page.application.enabled=true
BTW, it is rather annoying in dev instances, as it takes a while to load pages in the first access, sometimes you even need to reload the page. Also, be aware, in some especial cases, some applications might break, normally due to code that counts with page reloads to function properly.
you can even create it in 6.2 by using the following code.
// initializing senna
var app = new senna.App();
// Set links selector for navigations
app.setLinkSelector(".senna-link");
// set basic path of liferay site
app.setBasePath('/web/spa-demo/');
// Id of DOM element which will be replaced from
// next page request
// using content div - default in liferay theme
app.addSurfaces('content');
// define routes for all the navigation links
// route link = Base path + page link
app.addRoutes([
new senna.Route('home', senna.HtmlScreen),
new senna.Route('second', senna.HtmlScreen),
new senna.Route('third', senna.HtmlScreen),
]);
Thing which you need to take care of, if it is SPA, then all the events need to be bound first i.e. delegate as there is not going to be page refresh.
i.e things like document.getReady is only going to be called once.
Whatever the portlet you are going to create and deploy with Liferay SDK/Workspace OR any compatible liferay plugin it will be SPA by default.
No need to do any coding on top of it.

How do I modify the Site Collection in SharePoint 2013?

When I try to open a form published from InfoPath I now get this error:
"The following location is not accessible, because it is in a different site collection:
https//portal/sites/forms/Daily%20Activity/Forms/template.xsn?SaveLocation=https//portal.alamedacountyfire.org/sites/forms/Daily%20Activity/&Source=https//portal.alamedacountyfire.org/sites/forms/Daily%2520Activity/Forms/AllItems.aspx&ClientInstalled=false&OpenIn=Browser&NoRedirect=true&XsnLocation=https//PORTAL/sites/forms/Daily%20Activity/Forms/template.xsn."
Correlation ID:12c0ab9c-caff-80a8-f1b4-64d81dcfa6ea
Following are some options that you can try:
1) Save the form template (.xsn) as the source files in the publish options. Look at the manifest file in notepad and see if you can find a reference to the incorrect location. If so, correct it and Republish the form.
2) Clear the InfoPath cache on that machine. Start->Run "infopath /cache clearall"
3) See if the site collection has a managed path, if so, give the proper url while publishing. The XSN might be getting deployed on the root site and throws error since the intended list does'nt exist.
I found this worked for me. Got the answer from another post.
"I had a similar problem and found it was due to the request management service routing from my web application host header to the server name.
There was a routing rule in my request management settings. I just disabled routing and the problem went away. I used the following powershell to disable it. "
$w = Get-SPWebApplication "http://webapphostname"
$r = $w | Get-SPRequestManagementSettings
$r.RoutingEnabled = $false
$r.Update()
You may want to configure it rather than disable it. Here’s a good resource to get you started:
http://www.harbar.net/articles/sp2013rm1.aspx

Is it possible to change default sharepoint 2013 app url

The default app url looks like http://[app prefix]-[app id].[domain name]/[site collection path]/[app path]/pages/default.aspx.
It is unconvinient because every deployment during development generates new url. And after development stage the end users need a permanent link to the application, but every bug fixes or updates that will be deployed will cause new app url generation. Is there right way to fix the app url?
You can create a URL controller:
Create a list that would contain two fields: fakeUrl, realUrl,
fakeUrl can be something like "http://staticappname.[domain name]/[site collection path]/[app path]/pages/default.aspx"
realUrl would be your http://[app prefix]-[app id].[domain name]/[site collection path]/[app path]/pages/default.aspx
Give your users fakeUrl
Create a HTTPModule that would read the list and redirect the http request to the realUrl
After you redeploy your app, just change the realUrl in the list
***I'm not if this is your case but you could change your app to be a provider-hosted. Then you would get a static Url
You can open your SharePoint hosted add-in using an alternate link like:
http://[SharePointSite]/[Add-inName]
For eg.
http://contoso.com/sharepointhostedapp/

MVC Deployment resource URLS not resolving

My URLs aren't resolving correctly.
When I deploy my app name is omitted from the urls.
Its suppose to be:
http:////Content/images/ect
But it gets rendered as
http:///Content/images/ect
which obviously doesn't resolve.
My URLS looks like this:
<img src="/Content/images/Misc/Lock.png" />
If I add a ~ to the url (before content) it resolves perfectly when deployed, but breaks in my dev environment.
This being a MVC app means I also have a few ajax calls to actions (controller/action/) which also does not resolve, breaking most of the site.
I deployed under the default web site in IIS, moving it to another site is not an option.
Any advice will be greatly appreciated.
Have you tried using Url.Content?
It would be something like this (untested)
<img src="#Url.Content("~/Content/images/Misc/Lock.png")" />
This has to do with your host, if you are running this site as a sub site and not under its own IIS site, the host requires the ~. I have gotten around this by using a global javascript variable to hold the site root. I populate the variable in the main site layout like so:
var gSiteRoot = '#MvcHtmlString.Create(Url.Content("~/"))';
Then when I need to construct a url in js I use it like so:
var url = gSiteRoot + 'restofurl';

How do I force a new site collection to inherit a master page?

I have some code that creates a new site in SharePoint. Upon browsing to the newly created site, a File Not Found error is thrown. If you browse to /_layouts/ChangeSiteMasterPage.aspx you can select a new site master & system master page, and the site works fine. This kb article describes my symptoms perfectly: http://support.microsoft.com/kb/936908
My problem is that of the two (maybe three?) solutions given, only one works. If I manually select the new master pages it works fine. The second workaround is to activate the publishing feature on the new site. This does not fix anything.
There is also a recommendation to staple the publishing feature to the site definition I am using for the new site. In my case, this is STS#1 (the blank site), and stapling the publishing feature does not alleviate my problem.
Anyone have an idea of how I can get the correct master page sorted out?
We do this through a delegate control. In the OnLoad we call the following method:
private void ConfigureMasterPage(SPWeb web)
{
string masterURL = string.Empty;
masterURL = web.Site.ServerRelativeUrl + "/_catalogs/masterpage/XXX.master";
masterURL = masterURL.Replace("//", "/");
web.MasterUrl = masterURL;
web.CustomMasterUrl = masterURL;
web.Update();
}
Dont forget to do a dispose of the SPSIte and SPWeb objects and You will have to set AllowUnsafeUpdates to true.
Hope this helps
Turns out I just needed to change the master template in one of the generated sites and then save that as a template. I deleted the broken template and put this in its place. Now all the generated sites work fine.

Resources