FB_init

Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Monday, November 05, 2012

SharePoint - Displaying list items with line breaks

This is how you can display list items that have line breaks (based on SharePoint 2010)

1- With SharePoint Designer, open the site and the list.
2- Under the 'Forms' section, open 'DispForm.aspx'.
3- Find the section below and add the fragments in bold:


<asp:Content ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" id="onetidPageTitleAreaFrameScript">
if (document.getElementById("onetidPageTitleAreaFrame") != null)
{
document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";
}

// Custom below:
$(document).ready(function() {    
     //var content = $(".ms-rtestate-field").find('div').html();
     $('DIV.ms-rtestate-field').each(function(index) {
        var innerdiv= $(this).find('div');
        if(innerdiv) {
           innerdiv.wrap('<pre/>');
        }
 });
   });

</script>
</asp:Content>



4- Save

Note: to check if the list items are really storing the newline characters, you may use a CAML Query Builder.

Monday, November 21, 2011

My daily SharePoint frustration - XXI

Scenario: in a site with both forms and NTLM authentication, a user would add a List View Web Part to the page. The user would try to delete a document from it and an error appeared on the browser:



The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.


What I tried:
  I tried to add this to the custom master page (just before the closing form tag):



        

It didn't work. I saw no difference in the source html. And I noticed that the form digest information was always there, regardless.
  I also tried to add to the existing code behind of the custom master page:

  protected override void OnInit(EventArgs e)
        {
            if (Page.IsPostBack) // custom stuff 
           {
                Microsoft.SharePoint.Utilities.SPUtility.ValidateFormDigest();
            }

It didn't work.

I tried to remove my customized master page and to use an out-of-the-box SharePoint master page. The problem was still there. I then tried to use an out-of-the-box page layout. The problem was still there. I tried to create a brand new out-of-the-box web application. The problem was not there. I then went back to web site where the problem was happening and began to comment out the http modules in web.config - trying different combinations to isolate the HTTP module. And I zoomed in to one module. I also changed the order of the http modules. Still, the same http module was the one.
Even after I found the faulty http module, it was not easy to isolate the problem.  I had to comment out the different conditions until I isolated SPContext.Current. 

Solution:

( It depends on your environment... It may not be applicable to you )  
Changing the HTTP module so that the evaluation of SPContext.Current only happens after the verification that the current handler is a Page. :

   public class MyMengaoModule : IHttpModule

        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute +=
            new EventHandler(ContextPreRequestHandlerExecute);
        }

        void ContextPreRequestHandlerExecute(object sender, EventArgs e)
        {
            Page page = HttpContext.Current.CurrentHandler as Page; // new stuff

            if (page == null)
            {
                return;
            }

            if (SPContext.Current != null && SPContext.Current.Site != null && SPContext.Current.Site.Zone == SPUrlZone.Internet) // as it was before
            ...

Time it took me to fix the problem: 3 days of work...


Wednesday, November 16, 2011

Permission mask utility for SharePoint (2010)

Here is an utility for translating permission masks in hex to SPBasePermissions values.Click below to download.





The core of the thing:

private void button1_Click(object sender, EventArgs e)
        {
            string userValue = textBox1.Text;
            listBox1.Items.Clear();
            long valueOriginal = long.Parse(userValue, NumberStyles.AllowHexSpecifier);
            long value = valueOriginal;
            int rbit = 0;
            do
            {
                int i = (int)(value % 2);
                long bitcheck = 1 << rbit;
                if (i > 0) // it matches
                {
                    string name = "" + ((SPBasePermissions)bitcheck);
                    string formatString = String.Format("{0,10:X}", bitcheck);
                    Console.WriteLine(name + " " + formatString);
                    listBox1.Items.Add(name + " " + formatString);
                }

                value = value >> 1;
                rbit++;
            } while (value > 0);
        }

A screenshot:

Monday, November 14, 2011

My daily SharePoint frustration - XX

(With SharePoint 2010)

The actions:
 - I edited a page to add a document library to it. When I tried to click on an item's menu (the ECB), I got an error dialog  saying "This item is no longer available. It may have been deleted by another user. Click 'OK' to refresh the page. "

I tried different things:

  - I couldn't use SharePoint Designer. It failed to edit any page in my case. So I couldn't follow these instructions to substitute ListViewWebPart  with XSLTListViewWebPart.

- I changed the code and assigned the website's ID to ListViewWebPart.WebID. That made no difference for me. (It worked for some other people. Probably because the underlying problem is different).

- I installed this hotfix: http://support.microsoft.com/kb/2405789 . It didn't work.

What worked for me was to edit the web part and uncheck some options (not sure exactly which one):

- Toolbar type: None (this alone may do the trick)
- Checked Enable Asynchronous Load, Enable Asynchronous Update, Show Manual Refresh Button and Enable Asynchronous Automatic Refresh.
- I unchecked Enable Data View Caching.

Thursday, September 30, 2010

My daily SharePoint frustration - XIX

This error happened with SharePoint Server 2010.

The error:


********** ERROR: The template you have chosen is invalid or cannot be found.

STACK:    at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
   at Microsoft.SharePoint.Library.SPRequest.ApplyWebTemplate(String bstrUrl, String bstrWebTemplateContent, Int32 fWebTemplateContentFromSubweb, Int32 fDeleteGlobalListsWithWebTemplateContent, String& bstrWebTemplate, Int32& plWebTemplateId)
   at Microsoft.SharePoint.SPWeb.ApplyWebTemplate(String strWebTemplate)
   at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPContentDatabase database, SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, String quotaTemplate, String sscRootWebUrl, Boolean useHostHeaderAsSiteName)
   at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)
   at Microsoft.SharePoint.Administration.SPSiteCollection.Add(String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)
[...]

What I was trying to do: 
  I was trying to create a site collection with a custom template.

The cause of the problem:
   I was following some instructions from internal documentation on how to localize the site. One step instructed me to copy the site template XML file from the English directory to 

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LCID\XML
  
  After I deleted the XML files from both English and Japanese sites, the problem went away. I didn't try to delete just from the Japanese directory.


Tuesday, March 10, 2009

My daily SharePoint frustration - XVIII



The Problem: I can't save a file with Microsoft Office SharePoint Designer 2007 SP1.
There is no information in the error message.

Solution: none.

Tuesday, February 03, 2009

My daily SharePoint frustration - XVII

Problem: You cannot add data to a list though a site definition ( ONET.XML ) for a list instance created by a Feature. In a site definition you may instantiate a list and add data (rows) to it by using the Lists/List elements, but it will always be brand new list instances. There is no way to reference a list instance created by the Feature and just add rows to that list.

Solution: none.

Workaround: Set the list in ONET.XML to be a 'temporary list'. Have the Feature to also declare a (main) list instance. Both lists are of the same type. Upon site creation, have code to copy over the data from the temporary list to the main one, and delete the temporary list.

Friday, December 26, 2008

My daily SharePoint frustration - XVII

Problem: The data of a list wasn't exported when I saved the list as a template with content.

Context: I created a list using a Feature with schema.xml and manifests for list instance and list template. My custom fields were not showing up in the list settings under columns. And data wasn't exported.

Cause: I had my fields set as read-only in schema.xml (Fields/Field elements).

Solution: I removed the attribute and it worked. I had set them to read-only for performance in the first place. I don't think it makes much of a difference anyways.

Thursday, December 18, 2008

My daily SharePoint frustration - XVI

Problem: Browser displays "403 forbidden" in SharePoint with Forms authentication. (again! See frustration number XV)

Context: nothing out of the ordinary... Just working with some custom authentication providers as usual.

Cause: unknown.

Solution (?): Windows update plus reboot.

see also this discussion thread.

Tuesday, December 09, 2008

PowerShell and SharePoint: Feature localization

I needed to find out how many SharePoint Features are not localized in the solution.
So I created a PowerShell script that searches for feature.xml and other manifest files. Then it checks for Description or Title without the $ character (localized Descriptions and Titles begin with $Resources: )

Here it is:

$Dir = get-childitem c:\VivaOMengo -recurse -Include feature.xml
$SDir = $Dir | Select-String -CaseSensitive -Pattern "Description=""" | Select-String -NotMatch -Pattern "Description=""\$" | Select-String -NotMatch -Pattern "Description="""""
$Dir | Select-String -Pattern "Description=""" | Select-String -NotMatch -Pattern "Description=""\$" | Select-String -NotMatch -Pattern "Description=""""" > c:\VivaOMengo\nonlocfeatDesc.txt
Write-Host 'Feature.xml files containing non-loc Description: ' $SDir.count

$SDirT = $Dir | Select-String -CaseSensitive -Pattern "Title=""" | Select-String -NotMatch -Pattern "Title=""\$" | Select-String -NotMatch -Pattern "Title="""""
$Dir | Select-String -Pattern "Title=""" | Select-String -NotMatch -Pattern "Title=""\$" | Select-String -NotMatch -Pattern "Title=""""" > c:\VivaOMengo\nonlocfeatTitle.txt
Write-Host 'Feature.xml files containing non-loc Title: ' $SDirT.count

$DirM = get-childitem D:\projects\main_1\src\Channel\portal -recurse -Include *.xml
$DirM = $DirM | where { $_ -match "WSPBuild" } | where { $_ -notMatch "feature.xml" }

$SDirM = $DirM | Select-String -CaseSensitive -Pattern "Description=""" | Select-String -NotMatch -Pattern "Description=""\$" | Select-String -NotMatch -Pattern "Description="""""
$DirM | Select-String -Pattern "Description=""" | Select-String -NotMatch -Pattern "Description=""\$" | Select-String -NotMatch -Pattern "Description=""""" > c:\VivaOMengo\nonlocmaniDesc.txt
Write-Host 'Other manifest files containing non-loc Description: ' $SDirM.count

$SDirTM = $DirM | Select-String -CaseSensitive -Pattern "Title=""" | Select-String -NotMatch -Pattern "Title=""\$" | Select-String -NotMatch -Pattern "Title="""""
$DirM | Select-String -Pattern "Title=""" | Select-String -NotMatch -Pattern "Title=""\$" | Select-String -NotMatch -Pattern "Title=""""" > c:\VivaOMengo\nonlocmaniTitle.txt
Write-Host 'Other manifest files containing non-loc Title: ' $SDirTM.count

Sunday, December 07, 2008

My daily SharePoint frustration - XV

Problem: Browser displays "403 forbidden" in SharePoint with Forms authentication.

Context: Trying to get extended site to display the right page for forms authentications.

Cause: IIS (7.0) thought that the anonymous user did not have access to the web site, so it was not redirecting (or displaying) the internal page (the custom page with form authentication) for login.

Composite problem: Trying to enable anonymous access to 'the entire web site' was hidden in Advanced Permissions. That's because the Default Zone in Central Admin for the NTLM site (the base site of the extended Forms one) did not have Anonymous enabled.

Solution: I went to the Default zone in Central Admin, enabled anonymous (temporarily) for the base web site). Then I was able to enable anonymous access to the entire web site in Advanced Permissions (in the base site).

(For the record: anonymous authentication in IIS for the extended site had the identity of the app pool and not IUSR (win server 2008) and also ASP.NET impersonation enabled)

Tuesday, November 04, 2008

My daily SharePoint frustration - XIV

Error: I can't get xsxsl extension to work within DataFormWebPart's XSL:

Error while executing web part: System.Xml.Xsl.XslTransformException: Execution of scripts was prohibited. Use the XsltSettings.EnableScript property to enable it.

...em.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, Stream results) at Microsoft.SharePoint.WebPartPages.DataFormWebPart.ExecuteTransform(XslCompiledTransform xslCompiledTransform, XsltArgumentList xmlArguments) at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTransform()


No resolution.

Wednesday, October 22, 2008

My daily SharePoint frustration - XIII

Of all things in SharePoint, the most undocumented, the most mysterious, the most unpredictable, and the most unstable is the DataFormWebPart.

Tuesday, October 21, 2008

My daily SharePoint frustration - XII

The error: "an unexpected error"



The context: changing web parts, changing lists, changing list templates with a Feature.

The solution: Clear cookies and offline data files from IE (!), close all browser instances, do an iisreset.

Friday, October 17, 2008

My daily SharePoint frustration - XI

The error: access denied

Context: trying to access a web site (MOSS + WSS).




Solution: 1- delete offline content and cookies from IE, close all instances. 2 - delete web application from central admin, create new web application from central admin. 3 - you may need to grant access to the app pool user in SQL Server too.

Thursday, October 16, 2008

My daily SharePoint frustration - X

Note to self: when redeploying a Feature, delete all dependencies, such as lists and site columns.

Wednesday, October 15, 2008

PowerShell and SharePoint

I like to use PowerShell to read from SharePoint. It also allows me to debug quickly.
Here's an example of a script to list all lists from a web site.






$siteName = 'http://localhost:81'
# param([string] $siteName)


[void] [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint' ) | Out-Null

$site = New-Object -TypeName Microsoft.SharePoint.SPSite $siteName
[Microsoft.SharePoint.SPWeb] $web = $site.OpenWeb()
[Microsoft.SharePoint.SPListCollection] $lists = $web.Lists
Write-Host $sites.Count
[Microsoft.SharePoint.SPList] $list = $null

[int] $iList = 0
for($iList = 0; $iList -lt $lists.Count; $iList++)
{
$list = $lists[$iList]
Write-Host $list.Title $list.TemplateFeatureId $list.BaseTemplate $list.ID

}


Write-Host 'The end'

Tuesday, October 14, 2008

My daily SharePoint frustration - IX

The problem:
My custom list item form (custom ASP.NET page) for a new item wouldn't appear.

The symptom:
When I went on to create a new item, I got the standard SharePoint page and not my custom ASP.NET page.

Details:
I was setting up a Feature with a list template. I had a schema.xml file and a NewProductForm.aspx generated from SharePoint Designer. I put NewProductForm.aspx in the same directory of schema.xml and changed the Forms section in schema.xml to 'register' the new form.

The fix:
Removing the SetupPath attribute from the Form element solved the problem.

What led me to the fix:
I said 'abracadabra', threw salt over my left shoulder, read about How SharePoint Forms Work and this article about Custom List Feature Definition.

Time wasted:
3 hours