We have developed an internal portal with multiple subsites using sharepoint office 365. We created our own page layouts/masterpage for the sites and most of the things like menu's, page body and page logos are customized(unique for all sites/subsites).
Each page has a header logo and a url assigned to that logo(logo describes site or subsite name). We have written a javascript file to load these logo and url and calling on the masterpage. Now the problem is these logo and link should load based on Global navigation
Example:
If the site is using the same navigation items as the parent site?
Yes - pull logo and link from site above
No - pull logo and link according to site name
if i get the GlobalNavigation setting value then i can do this in javscript file. Is there a way to get this GlobalNavigation setting value in javascipt file? I googled on this but didn't get enough information.
Thanks in advance,
Amarnath
--------UPDATED-------
I am using the below code but getting error "sp.runtime.js:2 Uncaught Error: The property or field 'Source' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested"
used code
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
//Navigation Provider Settings for Current Web.
var webNavSettings = new SP.Publishing.Navigation.WebNavigationSettings(ctx, web);
//Global Navigation (Top Navigation Bar)
var navigation = webNavSettings.get_globalNavigation();
navigation.set_source(1);
webNavSettings.update();
ctx.executeQueryAsync(onSuccess, onFailure);
Related
This is very strange issue.
After installing the Microsoft Identity Web nuget package and setting up the app with razor pages, when I'm re-directed back to the app following an MS Sign out routine, i find that the logo image is no longer showing on the navbar.
This seems to be happening because the Microsoft Identity Web package is changing the URL of the page after signout i.e. its referencing a signout page that is now provided as part of the baked in package hidden away in one of the MD dll files.
My native javascript code is trying to load the logo image from my Images folder located on the root directory of my wwwroot folder structure, but because the signout page is changing the URL structure by adding a different path reference for the razor page, it's losing the path required for the image, not sure how to fix this?
js code that loads the image:
document.getElementById("navbarLogo").src = 'Images/CompanyLogos/Logo-LightTheme543by140px.png';
This image shows OK when I'm signed in normally or just browsing the site before sign in, so the issue only appears after being re-directed back to the site after an MS Sign out authentication flow.
The error shows 404, indicates that the image is not found, isn't blocked by identity. The image url may in layout, but the sign out page may not refrence the layout correctlly, or the relative path is not set corrcetlly. If it is not the problem, you can share this page code.
In the end I derived up the following solution which gave me what I needed:
// Because I'm using nested folders for the razor pages
// directory then I needed to re-construct the url path to
// to the images folder on wwwroot.
var urlPath = window.location;
var domain = window.location.hostname;
var port = window.location.port;
var baseUrl = 'https://' + domain + ':' + port;
Then using the above:
document.getElementById("navbarLogo").src = baseUrl + '/Images/CompanyLogos/Logo-LightTheme543by140px.png';
Poss not the cleanest solution but still works for me...
I have set up a SharePoint Online site and I have created a provider hosted app. One of the features of the app is to create subsites and there are times when a subsite needs to be renamed, including renaming the subsite URL. I can use the CSOM to create the subsite without any problems but when I try to rename the URL I get an access denied error. If I only change the title and description of the subsite there is no problem. If I log into SharePoint Online via the browser (using the same user account!) and I use the UI to rename the URL then it works without any problem. The page in SharePoint I use to rename the URL is https://tenant.sharepoint.com/testproject/_layouts/15/prjsetng.aspx
I have tried this on both a Microsoft 365 Developer subscription (where I am doing most of my development and testing) and the main SharePoint Online site where the solution will eventually be deployed to. I don't know much of the details for the main SPO site, other people set it up and I was provided an account to test renaming the subsite. To be clear, I am able to rename the subsite URL via the UI in both the developer and main SharePoint Online sites.
Is there something I'm doing wrong? Is there a limitation to renaming a subsite URL via code in SharePoint Online? Is there a bug in SharePoint Online that prevents renaming a subsite URL using code?
The exception thrown includes ServerErrorTypeName = "Microsoft.SharePoint.SPException". I can get the correlation id but from what I understand that's of no use in SharePoint Online. The exception Message is literally "Access denied." There is no inner exception.
Here is the code I'm using to rename the subsite:
SharePointContext spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
ClientContext clientContext = new ClientContext(spContext.SPHostUrl)
{
Credentials = new SharePointOnlineCredentials("SPUserName", "SPPassword".ToSecureString())
};
var webUrl = request.OldProjectUrl;
var subweb = clientContext.Site.OpenWeb(webUrl);
clientContext.Load(subweb);
clientContext.ExecuteQuery();
subweb.Title = request.ProjectName;
subweb.Description = request.ProjectName;
subweb.ServerRelativeUrl = "/HardcodedForTesting"; // <-- if I skip this line there is no error
subweb.Update();
clientContext.ExecuteQuery();
I was trying to achieve the same result but encountered the same error.
I was able to solve this by disabling the NoScriptSite setting of the site collection.
Using the PnP.PowerShell module:
Set-PnPSite -NoScriptSite:$false
Also the value you give to the ServerRelativeUrl property must be correctly constructed. I found two allowed format:
/sites/site-collection-path/new-subsite-path
new-subsite-path
Just did a test on my environment, I could rename the subsite URL via CSOM code normally. I use the same code as yours.
For your issue, you'd better create a service request with Microsoft.
I want a link that the users can click which supports logging in as a different user and then redirects them back to the same page.The issue is the page currently the user is on is also a layouts page .So the below code will work but take the user to the home page not the layouts page they are currently on which is
http://test.net/_layouts/15/EditProfile.aspx
function ChangeLogin()
{
var url = window.location.host;
alert(url);
var loginurl ="http://" + url + '/_layouts/closeConnection.aspx?loginasanotheruser=true'
location.href = loginurl;
}
Thanks
Method 1:
This can be done if you have access to the 2013 server 15 hive. Open 15 hive --> Control Templates-->welcome.ascx . Add the below xml entry:
<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
MenuGroupId="100"
Sequence="100"
UseShortId="true"
/>
Note: This is a farm level change and will affect all web application and sites on that server.
Method 2:
In the page where you want to add the link to add below tag:
Sign in as diff user
LoginAsAnother() is the method used by SharePoint internally in the method 1(ie OOTB menu under logged in user name).
Here provide the server relative web url before '/_layouts/15/closeConnection.aspx'.
So let's say I have a full url into a sharepoint website.
In the past when I wanted to get the weburl and doc url, I used the "url to web url" method of the Front Page Server Extensions. (http://msdn.microsoft.com/en-us/library/ms460544.aspx).
So for example if you had a site at
http://webapp/site1/chidsite/a.doc
I want a method in CSOM that will return /site1/childsite as the weburl.
I see the Web.WebUrlFromPageUrlDirect() method in CSOM but I'm not sure I'm getting what I need back from it. In the Uri class I get back, would I use teh "AbsolutePath" property for the weburl?
What is the correct way to do this?
I also would like to get the docURL that is usually retrieved by a call to url to web url via frontpage extensions.
The fileurl will be the file location relative to the web site. So if the document is stored in the document library called "Documents", you will get a value of /Documents/file.ext.
Well, I've reverted to using the FrontPage extensions when doing URLToWebURL since I just wasn't sure what I was getting using CSOM methods. Though check the link below for answers I received elsewhere.
Information Pertaining to this issue
I have a document library in a sub site. How do I add a link to that library into the root site's left navigation bar?
Dynamic or static links are fine.
Assuming you mean the Quick Launch (which is the left-side navigation shown in most non-application pages), then click "Site Actions", and choose "Site Settings". Under "Look and Feel", pick "Quick Launch". You can add the sub site's document library as a heading of its own, or as a link underneath any heading (it really doesn't matter too much outside of design perspective). This method is best for static links, of course.
The Quick Launch is not restricted to the current site: you can link any external URL you have. The document library of the subsite, basically, is treated as an external URL to the root site. Just make sure you use the full URL, then there's no chance for failure.
This should do it, if you want to do it programmatically:
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
var navigationNode = new SPNavigationNode("stackoverflow","http://www.stackoverflow.com", true);
web.Navigation.QuickLaunch.AddAsLast(navigationNode);
web.Update();
}
}