Monday, December 10, 2012

SharePoint 2010 Best Practices: Asset Versus Picture Library

If you have pictures, you have the choice to either store them in an asset library or a picture library. What is the best practice here?

Asset library (a media library)
More info about the asset library: http://office.microsoft.com/en-us/sharepoint-server-help/set-up-a-library-to-store-image-audio-or-video-files-HA101828004.aspx  Pros:
- Has in-built support for the new digital asset content types: image, video, and audio files.
- Has a default thumbnail-centric view.
- Has an image preview.
- Supports automatic metadata extractions (and promotion) for the following image types: BMP, GIF, ICO, JPEG, PNG, and TIFF.
- Podcasting support thru RSS feature.
- Supports metadata navigation (see https://www.nothingbutsharepoint.com/sites/eusp/Pages/SharePoint-Asset-Library.aspx  )
- Has a standard SharePoint 2010 menu (and therefore, has ribbon support).
-Centralized repository setup for digital assets (image, video, and audio files) for the organization.
- Allows Edit in Datasheet View, the Picture library does not. This makes bulk metadata management a lot easier.
Cons:
- Does not create a slide show of the pictures. This is an often used feature in Intranets. Example: A news article with a direct link to the slide show view of your company's last event or party.
- Although it is possible to email a link to the file (as is also the case in a Picture library), you can't easily embed them in an email or Word document. If you want to do this, you need to manually download the files you want to embed and add them manually to the email/document.
Picture library
More info about the picture library: http://agsci.psu.edu/it/how-to/use-picture-library-in-sharepoint-2007  Pros:
- Has a slideshow view of the pictures it contains.
- Can only contain pictures and is optimized for that.
- you can embed a picture directly into an email or Office document using the "Send To" action menu item.
- You can use the /_vti_bin/imaging.asmx web service to execute Upload/Download and other operations related to picture libraries: http://msdn.microsoft.com/en-us/library/imaging.imaging_members(v=office.12  ). Asset libraries don't have such a service.
With a Picture Library, users can easily send pictures (one or more) in an email (embedded in the body or as an attachment) or automatically add them to a Word document. With an Asset Library, users must download the files and manually create the email / document. Both have the option email a link to the file.
Cons:
- Does not have the larger thumbnail option of a picture when you hover over the item.
- The library menu is 2007 style, and thus looks different from other SharePoint 2010 libraries.
- Has a complicated way of uploading pictures using the "Picture Manager" application.

Conclusion
For pictures, the asset library represents the new choice towards the Digital Asset Management way of working SharePoint is striving towards. For pictures, it's the preferred choice, unless you really need a slideshow view. For other types of content, the asset library is the way to go.

Credits:
This Wiki page was inspired by the discussion at http://social.technet.microsoft.com/Forums/en-US/sharepoint2010general/thread/1272cf0c-095f-40d5-bde1-49f1fff70ba1Please note: Also check out the SharePoint 2010 Best Practice Overview page athttp://social.technet.microsoft.com/wiki/contents/articles/8666.sharepoint-2010-best-practices-en.aspx

More:
http://office.microsoft.com/en-us/windows-sharepoint-services-help/working-with-sharepoint-picture-libraries-HA001123335.aspx

https://www.nothingbutsharepoint.com/sites/eusp/Pages/An-Interesting-Thing-About-SharePoint-Picture-Libraries.aspx

Open an HTML or PDF files in SharePoint 2010


When you try to open a PDF file it prompts you to save it rather than opening.
Opening PDFs in SharePoint 2010
This is a security feature of SharePoint 2010 by design which adds headers that force the browser to download certain types of files like PDF, HTML etc. The forced download improves security for the server by disallowing the automatic execution of Web Content that contributors upload. In 2010 where we have a JavaScript Object Model, this would be a big problem if we did not have this restriction in place. This should be disabled at web application level which means across all the site collections, we cannot do at site level or site collection level.
If we disable this feature, we might have issues mainly if users try to upload HTML or other files which contain some malicious scripts.
If we want to enable this, we need to make sure that the users are not uploading any scripts (mainly Javascript) directly to Production without any testing on TEST environments.
Never fear there is a solution. It’s in central admin.Go there and click ‘Manage Web Applications’
Opening PDFs in SharePoint 2010Click on the web app you want to change, and go to ‘General Settings’
Opening PDFs in SharePoint 2010Scroll down the list until you reach ‘Browser File Handling’
Change the radio box from Strict to Permissive.
Opening PDFs in SharePoint 2010Click ok.
Go back to your PDF document and click on it – and it will open up without forcing you to save it somewhere first.




Retrieve all the files in a folder and their subfolders using VBScript or C#

To get all the files in folders and their subfolders of a given directory in an hirarchial format into a text file

' VBScript

1. Create a .txt file and paste the below vbscript code into that and save the file with .VBS extension.
2. Change the source folder path and destination path.
3. Then double click on the .vbs file, it will take few seconds and generate a text file with the details on the given path.

Dim oFSO, oFldr

set oFSO = CreateObject("Scripting.FileSystemObject")
Call Folders()

Function Folders()
set oFldr = oFSO.GetFolder("D:\Projects")
call GetSubFolders()
End Function

Function GetSubFolders()
for each files1 in oFldr.Files
call WriteFile(oFldr.Path & " " & files1.name)
Next
for each subFldr in oFldr.SubFolders
for each oFldr in subFldr.SubFolders
Call GetSubFolders()
next
for each files in subFldr.Files
call WriteFile(subFldr.Path & " " & files.name)
Next
next
End Function
'This works for both .txt & .xls. To use it for xls, just change the extension below to .xls.
Function WriteFile(strFiles)
if not oFSO.FileExists("D:\Projects\FilesIndex.txt") then
set f = oFSO.CreateTextFile("D:\Projects\FilesIndex.txt",1)
Else
set f = oFSO.OpenTextFile("D:\Projects\FilesIndex.txt", 8)
End if
f.WriteLine(strFiles)
f.close()
End Function


' In C# code for the same..
    'private void Folders()
    '   {
    '       DirectoryInfo dir = new DirectoryInfo("D:\\SiteMaker\\Root\\");
    '       //DirectoryInfo dir = new DirectoryInfo("D:\\SiteMaker\\images");
    '       GetSubFolder(dir);
    '   }

    '   private void GetSubFolder(DirectoryInfo dir)
    '   {
    '       foreach (FileInfo files1 in dir.GetFiles())
    '       {
    '           strFiles.Add(files1.FullName);
    '       }
    '       foreach (DirectoryInfo subDir in dir.GetDirectories())
    '       {
    '           foreach (DirectoryInfo dir1 in subDir.GetDirectories())
    '           {
    '               GetSubFolder(dir1);
    '           }
    '           foreach (FileInfo files in subDir.GetFiles())
    '           {
    '               strFiles.Add(files.FullName);
    '           }
    '       }
    '   }

Thursday, December 6, 2012

SharePoint 2010: An error occured while rendering navigation for requrested URL. Exception message: Cannote complete this action.


An error occurred while rendering navigation for requested URL. Exception message: Cannot complete this action.Microsoft.SharePoint.SPGlobal.HandleComException...

One of the user was reported with the above error message while accessing a SharePoint 2010 Publishing site.


The actual root cause of the issue the Navigation Settings. When I try to open the navigation settings page (/_layouts/AreaNavigationSettings.aspx) on the site, we are getting an "Server Error in '/' Application". This is the second time I was reported on the same sort of issue, but this time from a different user on different site (even different site collection, but on the same web application). And again the user was not sure which page/s were causing the issue.
Based on the recent modified pages in reverse order, I keep going deleting them as I know that I can restore them back once the issue fixed. As soon as I deleted the issue causing page, I was able to access all the settings pages including Navigation Settings. Then I went and deleted the page URL in the Navigation Settings section and restored all the pages which were deleted including the root cause page as the issue was not with the page, issue was with the Navigation URL of the page. Not sure exactly what was the issue with the Navigation URL as it looked good to me before I removed.
There I observed an uncommon behavior at Global Navigation settings like the page which was causing the issue with its name, few folders were added. I just deleted them and monitored for some time, that did not repeated. Happy ending....

Please see more information on the same issue:
SP 2010: Error when opening _layouts/AreaNavigationSettings.aspx

Imp: Avoid adding a document URL or List/Document Library URL to site Navigation (if it has a mile long) instead place it in a page and use that page URL in the Navigation.

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.

Tuesday, September 25, 2012

About SharePoint 2010 Variations



The variations feature in Microsoft SharePoint Server 2010 makes content available to specific audiences on different sites by copying content from a source variation site to each target variation site. When users visit the root site, they are redirected to the appropriate variation site, based on the language setting of their Web browser. If necessary, the content can be customized on the target variation site. 
For example, content on a target variation site can be translated into other languages before it is published. 

Variations can be used only on SharePoint Server 2010 sites that are created with one of the Publishing site templates, or on sites for which the SharePoint Server Publishing Infrastructure feature has been enabled.

Uses and benefits of variations
Many organizations have a global reach. However, even in domestic markets, organizations must reach a diverse customer base that might speak many different languages or that might need to have specific information that is based on regional differences, on various mobile devices, or on corporate branding. These types of organizations need Web sites that deliver tailored content to suit different cultures, different markets, and different geographic regions. Producing and maintaining variations of a site can be difficult and time-consuming. By using variations as part of a SharePoint Server 2010 solution, site architects and site administrators can simplify the process of producing and maintaining these sites. The variations feature automates the creation of sites and pages, which eliminates having to manually create a site and all associated pages for each instance of a needed variation.

Scenarios for using variations
You can use variations to create different versions of similar content for users in many scenarios. The following table describes possible scenarios in which you might use variations.


Scenario
Description
Multiple languages
You can use variations to create sites and content for specific languages. In this scenario, the majority of the content is authored in the language of the source variation site and copied to some or all of the target variation sites for translation into different languages. For example, the content might be authored in English and be copied to target variations sites for translation into German, French and Spanish.
 devices
You can customize the logic of the VariationRoot.aspx page to direct users to pages that are designed to work with different types of devices. For example, you might have target variation sites with pages designed for display on devices that have different screen sizes or screen resolutions.
Multiple locations 
or brands
You can use variations to create content for specific locations or brands. For example, a rental car company might have target variation sites for all the cities in which they have branch offices. Most of the company information is the same across branches, so variations are used for those pages, while other content, such as special offers or promotions, is created on the target variation sites for which it is needed.



Elements of variations
The variations feature consists of the following elements:
  • Variation root site   The variation root site provides the URL for all source and target variation sites and contains the landing page that redirects users to the correct variation site. This is not the same as the root site of a site collection, although you can specify the root site of a site collection to also be the root site of the variations hierarchy.
  • Variation labels   A variation label is an identifier that names a new variation site. Variations of a site are defined by creating variation labels, one for each planned variation.
    Note: SharePoint Server 2010 supports up to 50 variation labels.
  • Variation sites   The variation sites are the sites that are created based on the defined variation labels. There are two types of variation sites:

    • Source variation site   The source variation site is the site where shared content is authored and published, and it is the site from which copies of the shared content are sent to the target variation sites. There can be only one source variation site in a single site collection. After a source variation site has been selected, it cannot be changed.

    • Target variation sites   The target variation sites receive most of their content from the source variation site. Although new content can be created on a target variation site, that content is not shared with other sites and is unique to the site on which it was created.
  • Variations hierarchy   The variations hierarchy is the entire set of sites in all variation labels.
  • Variation pages   Variation pages are the publishing pages that are stored in the Pages library of the source variation site and the target variation sites. These pages and any dependent resources such as images and documents are the only content that is copied from the source variation site to the target variation sites.


--------------------------------------------------------
About me: 
Vishnu Vadla, Dallas, TX.
SharePoint Consultant.

Specialized on Microsoft Technologies 
(SharePoint, ASP.NET, SQL Server Technologies)
--------------------------------------------------------