Tuesday, November 27, 2012

Show/hide web part with the use of a simple HTML button and java script.


I want to show or hide a web part on a page with the help of a simple HTML button.
SharePoint 2010, "Edit HTML source" feature (see image) helps a lot in doing so, as, with its help you can put an existing web part in a DIV tag and then you can change the 'display' property of that DIV tag.
As soon as you click on this the window that will open up will have a small code for your web part (that you want to show/hide).
Just at the start of that code write your DIV tag and also supply an ID to it, say,
<div id="Toggle" style="display: none;">
..... - web part code - ....
</div>
JavaScript:
Write a small code, that will look something like this:
-------------------------------------------------------------------------------------------
<html>
<head>
<script type="text/javascript" language="javascript">
function ShowWeb()
{
if (document.getElementById("Toggle").style.display == "block")
         {
           document.getElementById("Toggle").style.display = "none";
         }
         else
         {
           document.getElementById("Toggle").style.display = "block";
         }

}
</script>
</head>
<body>
<input name="Button1" type="button" value="Show/Hide" onclick="ShowWeb()" style="width: 140px; height: 40px">
</body>
</html>
-------------------------------------------------------------------------------------------------------
Save this in a text file and upload it on your site.

Go to the page again and add a Content Editor web (CEWP) part just above your main web part. Edit this CEWP and in the URL section give the URL of the text file.

SP 2010: Error when opening _layouts/AreaNavigationSettings.aspx

When one of the user, trying to open the navigation settings page (/_layouts/AreaNavigationSettings.aspx) on a SharePoint Server 2010 sub site, she encountered an "Unknown Error". When opening the default page, the Quick Launch navigation on that page was also displaying errors:

The quick launch navigation was changed manually and navigation items were added/removed. I started looking into the issue after four days later due to Thanksgiving holidays and she was not sure which page she was working when the error occurred.And I could not find much in the loga and even tried to see Audit Log to find out which page was causing the issue.Note: To configure Audit Log, Site Collection settings -> Site Collection Administration-> Site collection audit settings.If you don't find Audit Log reports, activate the Reporting feature under site collection features..Finally, I deleted all the pages as these pages were not containing much information then it worked well. And recreated them again. Still not sure which page caused the problem, however after almost a day spend on this, I could fix the problem. Obviously deletion of all the pages is not a solution, the other options I has was look into the backups (& restore in a test environment) which page was recently added to the Navigation.Thanks to Yorick (http://share-point.blogspot.com/2010/03/moss-unknown-error-when-opening.html) and Melonie Poole (http://blogs.catapultsystems.com/mpoole/archive/2010/11/22/unknown-error-in-sharepoint-2007-debug.aspx) for their posts on the same issue with MOSS 2007..

Wednesday, November 21, 2012

Install Active Directory Users and Computers for Windows 2008


On Win 2008 --> From Right click on Computer --> Manage (server manager), go to Features, then add
Expand:
  • Remote Server Administration Tools
  • Role Administration Tools
  • Active Directory Domain Services Tools
And then check Active Directory Domain Controller Tools
it includes:
  • Active Directory Users and Computers
  • Active Directory Domains and Trusts
  • Active Directory Sites and Services
Server 2008 R2 Instructions:
Under Role Administration Tools, expand
  • AD DS and AD LDS Tools
    • AD DS Tools
      • AD DS Snap-Ins and Command-Line Tools.



Once you install, you can open it as below:

  1. Click Start, and then click Run.
  2. In the Open box, type dsa.msc, and then click OK.
—or—
  • Click Start, point to All Programs, point to Microsoft Exchange, and then click Active Directory Users and Computers.
or
  • Click Start, point to All Programs, point to Administrative Tools, and then click Active Directory Users and Computers.


Wednesday, November 7, 2012

Hide Left Navigation and ribbon controls of SharePoint 2010


Add a Content Editor webpart on the page and use the below code in a the webpart, to hide the ribbon controls and the left nav bar.


<style>
#s4-leftpanel {
DISPLAY: none
}
.s4-ca {
MARGIN-LEFT: 0px
}</style>

Tuesday, November 6, 2012

Relative Paths in SharePoint 2010 using $SPUrl


Relative Paths in SharePoint using SPUrlExpressionBuilder ($SPUrl)

When you edit pages and/or master pages in SharePoint either for branding or some other project you will eventually come across the need to link to some resource file whether it’s an image, icon, CSS, etc. When this came up for me, I realized I had no idea how to do this properly.
Fortunately, some quick searching found the solution I needed. I came across Bugra Postaci’s blog post on the subject and that got me going. Be sure to check it out for some background, but the basic idea is to use theSPUrlExpressionBuilder class to generate relative links. Unfortunately, this class is part of the publishing namespace and so is only available in SharePoint Server (2010) and MOSS (2007).
He gives an example of linking to an image within the Style Library of the site collection using the following code directly within the master page:
<asp:Image ImageUrl="<% $SPUrl:~sitecollection/Style Library/CustomImages/BlogofBugra.jpg %>" runat="server" />
The key thing to note is the inline use of the $SPUrl command. The example shows this within an asp:Image control but this can be done in a standard tag as well (img, link, etc.).
After seeing that, I really wanted to know what other magic tokens you can use, but the Microsoft Documentaiton on the class doesn’t even show the inline $SPUrl syntax, let alone list any of the usable tokens! Doing a quick search will find you an assortment of undocumented tokens. However this can be misleading as the tokens listed in {} braces are generally only for custom actions and not for inline links (you can find examples of those lists here and here).
Token
Replaced By
Version
~site/
2007, 2010
~sitecollection/
2007, 2010
~language
2007, 2010
With the exception of the ~language token, the others are replaced using a call to Microsoft.SharePoint.Utilities.SPUtility.UrlFromPrefixedUrlCore.

Monday, November 5, 2012

Create an ASP.NET Page (Application Page) for SharePoint 2010/2013

  1. Visual Studio 2010 or 2013 --> New Project --> SharePoint --> 2010 node --> Empty SharePoint Project.
    Name: SharePointApplicationProject --> OK.
  2. The SharePoint Customization Wizard appears. This wizard enables you to select the site that you will use to debug the project and the trust level of the solution.
  3. Choose the Deploy as a farm solution option button, and then choose the Finish button to accept the default local SharePoint site.
  4. Right click on the project --> Add New Item --> Application Page, Name:TestPage.aspx
    The Visual Web Developer designer displays the application page in Source view where you can see the page's HTML elements. The designer displays the markup for several Content controls. Each control maps to a ContentPlaceHolder control that is defined in the default application master page.
  5. Use VS --> View --> Toolbox to drag and drop control on the source view. Under
    Under PlaceHolderMain add these tags

    <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />    
    <asp:listbox id="lstLists" runat="server"></asp:listbox>
    And in code behind
    protected void btnSubmit_Click(object sender, EventArgs e){SPWeb web = SPContext.Current.Web;lstLists.Items.Clear();lstLists.Items.Add("Lists in '" + web.Title + "' site");lstLists.Items.Add("");foreach (SPList list in web.Lists){    lstLists.Items.Add(list.Title);}}
  6. To execute the page, Solution Explorer --> Right Click on Application Page -->Set as Startup Item.
  7. F5..
  8. To use a different master page or your own custom master page use the below code

        protected override void OnPreInit(EventArgs e)

        {
            base.OnPreInit(e);

            SPWeb Web = SPContext.Current.Web;
            string strUrl = Web.ServerRelativeUrl + "/_catalogs/masterpage/v4.master";
            this.MasterPageFile = strUrl;
        }


Sunday, November 4, 2012

Microsoft.SharePoint.SPException : Cannot complete this action.\n\n Please try again.

Error: "Cannot complete this action.\n\nPlease try again." exception when trying to save data in a List Library. The full exception is:
Microsoft.SharePoint.SPException was caught
Message="Cannot complete this action.\n\nPlease try again."
Source="Microsoft.SharePoint"
ErrorCode=-2147467259
StackTrace:
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.Undirty()
at Microsoft.SharePoint.SPBaseCollection.System.Collections.IEnumerable.GetEnumerator()
at XXXXX.SharePoint.XXXXXX.XX_XXX_FormUC.SaveOrSubmitSOW(String strSaveOrSubmit)

And the line from which it has been thrown is:
foreach (SPListItem listItem in list.Items)

The code is connecting to the List but unable to read the data. Try to use SPSecurity.RunWithElevatedPrivileges to resolve the issue. If this does not work, try the below option...
If you have a Columns with type Hyperlink, sometimes (I guess) you will face this issue. You need to delete those columns and create again. If then also it doesnt work, change them to text mode and handle the hyperlink functionality in the code behind file.