I am completely puzzled with this:
I have a custom SharePoint site with QuickLaunch on the left and Top Navigation Bar (which are of course visible by default).
This custom site has several sub-sites, which all inherit navigation from the root site.
Everything works fine, but after application pool recycle both menus on the left and on top are disappearing when I enter any of the sites for the first time! After simple refresh everything is back to normal, all menus are visible.
After recreating the site and subsites they behave the same: on first visit - menus are not visible, after refresh they are visible and they stay visible until I make an application pool recycle.
Sometimes only one menu (top bar or quick launch) disappears and the second one is normally visible, and I also think I encountered a situation when it disappeared during normal using of the site, not after the recycle.
There is nothing in the EventLog. There is a trace in the ULS log, though. When quick launch or top bar disappears only one new line (yes, only this one, no stack trace or any further information) is added:
02/05/2010 10:24:19.18 w3wp.exe (0x171C) 0x17BC Windows SharePoint Services General 8kh7 High Cannot complete this action. Try again.
Well, indeed it says that something is wrong that is causing the menu to disappear. Can anyone help me how to diagnose this or maybe knows why these menus are disappearing?
Gylo do you have the Publishing feature enabled on those sites? This is a known situation when restoring saved site templates with publishing enabled (using a small hack) where the Top Navigation won't appear for the first time.
What version are you running? (Site Actions => Site Definitions shows it)
It may be that you messed with Navigation in site definition and removed Navigation Node with Id of 1002. This node is responsible for storing web Top Navigation, and even if your web uses shared navigation, you'll get disappearing navigation under some circumstances.
Check if your-web.Navigation.TopNavigationBar is null. If it is, that is not very simple to restore node #1002. Below is a patch I've written to fix this issue on production environment. Test it first!
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.OpenWeb("/information"))
{
if (web.Navigation.TopNavigationBar == null)
{
List<SPContentDatabase> contentdatabases = new List<SPContentDatabase>();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPNavigationNode node = new SPNavigationNode("", web.ServerRelativeUrl, false);
web.AllowUnsafeUpdates = true;
try
{
SPNavigationNodeCollection navigationNodes = null;
navigationNodes = web.Navigation.GlobalNodes;
navigationNodes.AddAsFirst(node);
}
finally
{
web.AllowUnsafeUpdates = false;
}
SPContentDatabase database = site.ContentDatabase;
using (SqlConnection con = new SqlConnection(database.DatabaseConnectionString))
{
con.Open();
using (SqlCommand command = con.CreateCommand())
{
command.CommandText = string.Format(#"UPDATE NavNodes
SET Url='', Eid={0}, ElementType=1, DocId=NULL
WHERE Eid={1}
and WebId='{2}'
and SiteId='{3}'",
1002,
node.Id,
web.ID.ToString(),
site.ID.ToString()
);
command.ExecuteNonQuery();
}
}
});
}
}
}
Related
I have written a fairly straight-forward JavaScript for SharePoint Online that I am deploying as a user custom action into the root site collection using CSOM.
The following code is the block I am using for provisioning the script to the site collection:
public static void ProvisionScriptLinkCustomAction(ClientContext ctx, string name, string url)
{
Site site = ctx.Site;
ctx.Load(site.UserCustomActions);
ctx.ExecuteQuery();
foreach (UserCustomAction action in site.UserCustomActions)
{
if (action.Name == name)
{
action.DeleteObject();
break;
}
}
ctx.ExecuteQuery();
UserCustomAction customAction = site.UserCustomActions.Add();
customAction.Location = "ScriptLink";
customAction.Name = name;
customAction.ScriptSrc = url + "?" + Guid.NewGuid().ToString();
customAction.Update();
ctx.ExecuteQuery();
}
I am logged in as the tenant administrator when deploying and initially testing the custom action. Everything works as expected until I log in as a user that is not the tenant admin. When logged in as any other user that is only a site collection administrator or lower, the custom action does not fire and all of my efforts are for naught.
This feels like a configuration or permissions issue to me but I am at a loss to begin to know where to look to rectify this issue.
Any helpful thoughts would be greatly appreciated!
Turns out I had console.log calls in my JavaScript. Some versions of IE apparently do not know how to log to the console when in browser mode without debug tools which presumably throws an uncaught and unlogged exception. Removing the console.log statements made the issue go away.
I have developed a windows phone 8 application. Now I want to display vserv ads to my application.
I have added the sdk to my application and also applied code to show ads:
public MainPage()
{
InitializeComponent();
VservAdControl VMB = VservAdControl.Instance;
VMB.DisplayAd(zoneID, LayoutRoot);
VMB.VservAdClosed += new EventHandler(VACCallback_OnVservAdClosing);
VMB.VservAdNoFill += new EventHandler(VACCallback_OnVservAdNoFill);
}
void VACCallback_OnVservAdClosing(object sender, EventArgs e)
{
MessageBox.Show("Ad close by user.");
}
void VACCallback_OnVservAdNoFill(object sender, EventArgs e)
{
if (adGrid != null)
adGrid.Visibility = Visibility.Collapsed;
}
But after closing the ad the application page goes blank, all content, application bar automatically goes blank. After using back arrow that quits my application, i try to relaunch my application but application stuck at the splash screen on the emulator.
Wrap ad control inside a grid. Ad control could have manipulated the grid
I encountered the same issue and they have updated their SDK several times. If you provide the stacktrace they will provide you a fix.
Apart from what you have seen, there are other issues with the SDK. I integrated it few weeks back. So issues could have been resolved after that.
Memory leak. Click the ad or navigate back and forth - you will see the memory ever growing. This is because of events not being detached (withing SDK). I was consistently able to see my app crash in 512 MB emulator when banner ad is loaded (after 4 - 5 times). They could have used weak listeners. You might need to tweak a lot to overcome this issue (In multi page app)
RequestAdCallback throws null pointer exception sometimes crashing
the app. When people use app, they will navigate fast - forcing the
webbrowser to unload. All callbacks should be null pointer exception
free. Make sure that you handle unhandled exception globally otherwise app will not pass certification
It reads WMAppManifest.xml as text not as XML. So I had App element commented in first line before the actual one. It picked title from commented XML element
Application bar is manipulated in many events in the SDK. So you have to make sure that app bar is built dynamically. Test all navigation paths.
SDK assumes user will click the left arrow button which fires ad closing event. Try pressing phone back button instead. The app bar still disappears
SDK documentation requests app to demand ID_CAP_REMOVABLE_STORAGE capability. I don't see a reason to request this capability but I didn't add this
I have emailed them all these details. May be their latest SDK could have resolved these issues. But please do thorough testing after integration.
Add a function to load applicationbar using code
private void BuildLocalizedApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = false;
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/sms.png", UriKind.Relative);
button1.Text = "sms";
ApplicationBar.Buttons.Add(button1);
}
and then in VACCallback_OnVservAdClosing event handler call the function
BuildLocalizedApplicationBar()
Please check the following link,
where to add application id and adUnitiD while integrating vserv ads sdk to windows phone 8 application, which is related to your question.
I have a SharePoint 2010 MySites set up on its own web application. There is the standard site collection at the base level, http://site:80/.
The personal sites for each user is at the managed URL /personal/.
I have a working event handler which add items to the Newsfeed when a user adds something to a picture library.
THE PROBLEM:
The problem is, this only works if they add to a picture library at the base site collection, http://site:80/, and does NOT work if they add to http://site:80/personal/last first/.
Does anyone know why? The event handler feature is site scoped and my understanding is that it should work on all subsites.
The problem is that personal sites are not subsites of My Site host. In fact each user's personal site is a site collection on its own. So basically you need to register your event receiver not only for My SIte host, but also for each user's personal site.
Ok. Because you can only 'staple' features to site definitions which will be provisioned in the future, you need a way to activate new features on existing sites.
So, the fix I discovered and used follows:
The default page for the newsfeed is http://site:80/default.aspx. If you create an event receiver and scope it for 'site' and deploy it globally or to that web application, then it will work on the base site collection. Each personal site is a site collection and has the feature but it needs to be activated on each personal site collection.
So, in the default.aspx page, you place the following which will activate the feature if it has not yet been activated.
<script runat="server" type="text/c#">
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
String sAccount = (((SPWeb)((SPSite)SPContext.Current.Site).OpenWeb()).CurrentUser.LoginName).Split('\\')[1];
String basePersonalURL = "http://site:80/personal/";
String eventReceiverFeatureId = "12345678-1234-1234-1234-1234567890ab";
using(SPSite site = new SPSite(basePersonalURL + sAccount)) {
site.AllowUnsafeUpdates = true;
using(SPWeb web = site.RootWeb) {
web.AllowUnsafeUpdates = true;
try { site.Features.Add(new Guid(eventReceiverFeatureId)); } catch {}
web.AllowUnsafeUpdates = false;
}
site.AllowUnsafeUpdates = false;
}
}
</script>
You also need to edit the web.config file in order to allow inline code to run for this page. Hope this helps.
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();
}
}
I'd like to expose a web part to some users, but not all of them. How can I show or hide a web part in the Add Web Parts pop up window? I'd like to do this through code, and I'm hoping to use SharePoint Roles to make this happen.
I know you can manage which web parts show up in the Add Web Parts window in the Web Part Gallery.
While I haven't done it... since it's just another SharePoint List, you should be able to programmatically assign roles to Groups/Users?
More Info...
Update - Since you want to see some code. Nothing special, just a quick hack. You'll definitely want to do your standard error checking, etc. HTH :-)
using (SPSite site = new SPSite("YOUR SP URL"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Web Part Gallery"];
// Your code for choosing which web part(s) to modify perms on
// will undoubtedly be more complex than this...
SPListItem listItem = list.GetItemById(19);
SPPrincipal groupToAdd = web.SiteGroups["YOUR GROUP NAME"] as SPPrincipal;
SPRoleAssignment newRoleAssignment = new SPRoleAssignment(groupToAdd);
SPRoleDefinition newRoleDefinition = web.RoleDefinitions["Read"];
newRoleAssignment.RoleDefinitionBindings.Add(newRoleDefinition);
listItem.RoleAssignments.Add(newRoleAssignment);
}
}
You can do this with SharePoint Groups.
Go to the Web Part Gallery, click "Edit" on the web part you wish to scope, then click Manage Permissions. Here you can specify which users or groups can use the web part.