AJAX and Publishing Pages

Last year I was working on a project and was required to use AJAX on a Web Part to display some things on a site.  No problem I thought.  Then, I had to enable this on a publishing site…problems begin.  Tried finding anything and everything regarding this problem and found that several people had the same issue.  I posted on forums, ran it past MS, co-workers, etc, no dice.  Today I was playing with a couple of other things and found the solution.  The issue is in the order of which the master pages display.  To make AJAX web parts work from a publishing site master page, you have to do the following:

1. Turn on AJAX for thw web.config (I follow Jan T’s solution for integrating AJAX the lazy way)

2. Create a web part page (ASP.Net AJAX project with 3.5) and use the UpdatePanel and the ScriptManager
        – There are several ways to do this without adding the ScriptManager to the .master page. 

3.  Make sure to add the EnsurePanelFix JavaScript thing…you can find that about anywhere on the net

4.  The most important thing, you have to make sure the master page is set up properly!!!!!!!!
         – For example, the default.master in SharePoint, works fine, however, blueband.master (and all the other ones in publishing “MasterPages”) have some flaws
                     – <Title>:  This is on separate lines, move this all together:
                    – SPWebPartManager: This needs to be Inside the <form> tag


If you use the default.master page that is in the publishing master pages, it works FINE...so the chance that they were close and the issue was in the master page was high.  I sure hope this helps someone else.

Links:
Walkthrough: Creating a Basic ASP.Net AJAX-enabled Web Part
Good reference, even though this is for the old toolkit. About everything here can be applied to the current stuff

SharePoint Warm Up Script

I have had a lot of people use my other warm up script that I created almost a year ago but several people have asked for one that actually works…doh.  You see, my old one just used the WebRequest object to hit the site.  That does NOT warm up the site.  You actually need to get content from the page first.

This new script is a complete one that can be scheduled on your WFEs.  If you didn’t know already, all the Application Pools that get created are scheduled to reset themselves at a certain time.  Usually around 2 AM in the morning.  So if you want, take this script and put it in a CMD or BAT file and put an IISRESET right in front of it.  Then, add the code I have provided in a PS1 script and you are off and gunning.  You can remove those app pool recycles that are scheduled.

Save the following in a script named SPWarmUp.ps1

############################################################################
#Assumptions:
#-Running on machine with WSS/MOSS
#-C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN in path
############################################################################
function get-webpage([string]$url,[System.Net.NetworkCredential]$cred=$null)
{
$wc = new-object net.webclient
if($cred -eq $null)
{
$cred = [System.Net.CredentialCache]::DefaultCredentials;
}
$wc.credentials = $cred;
return $wc.DownloadString($url);
}

#This passes in the default credentials needed. If you need specific stuff you can use something else to
#elevate basically the permissions. Or run this task as a user that has a Policy above all the Web Applications
#with the correct permissions
$cred = [System.Net.CredentialCache]::DefaultCredentials;
#$cred = new-object System.Net.NetworkCredential("username","password","machinename")

[xml]$x=stsadm -o enumzoneurls
foreach ($zone in $x.ZoneUrls.Collection) {
    [xml]$sites=stsadm -o enumsites -url $zone.Default;
    foreach ($site in $sites.Sites.Site) {
        write-host $site.Url;
        $html=get-webpage -url $site.Url -cred $cred;
    }
}

When you schedule this to run through a scheduled task, make sure the user running this has the correct credentials on the sites being hit.  Obviously, make sure this is on ALL WFEs.

Can you test this without all the other stuff?  Sure, just copy and paste the code and put it in to PowerShell and give it a whirl.

Download the file here

WSS/MOSS on Vista

It appears several have done this so I decided to make the jump.  Might I add…I LOVE THIS.  I took the plunge with MOSS since I tend to do most of my stuff in there.  Here is what you need:

 

http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/21/how-to-install-windows-sharepoint-services-3-0-sp1-on-vista-x64-x86.aspx

                This tells you about everything you need to know…

                Pay attention to the IIS part so you have everything configured

                One thing that bit me right away was that ASP.Net was defaulted to run as v1.1 so when Central Admin spun it was running under 1.1 at first

                You can do the DBA install by running psconfig BEFORE you run the config like we usually recommend

                Make sure to create local users on your machine.  If you are like me, I tried through the standard “User Accounts” interface and that doesn’t work.  Click the Advanced Tab and then the Advanced button to do it that way

 

I have not configured the SSP as of yet, nor will I until needed.  This rocks!

 

Here is my script to config the main site:

psconfig -cmd configdb -create -server oma-khofer -database MOSS_Config -admincontentdatabase MOSS_Admin_Content_01 -user oma-khofer\SPFarm -password pass@word1

 

#After this is done, launch the wizard…I know there is a command to do that via psconfig, but can’t remember

 

Also, if you have any problems, tear it down, it is easy…

 

#PoSH script of course

$sspname=”SSP1”

$databaseserver=”oma-khofer”

 

#Delete SSP

stsadm -o deletessp -title $sspname -deletedatabases -force

 

#loop through and delete all your web apps you created

stsadm -o unextendvs -url http://oma-khofer:84 -deletecontent -deleteiissites

 

#Delete CA

stsadm -o deleteadminvs

 

#Disconnect

psconfig -cmd configdb -disconnect

 

$databasename="MOSS_Config"

sqlcmd -S $databaseserver -Q "ALTER DATABASE [$databasename] SET SINGLE_USER WITH ROLLBACK IMMEDIATE"

sqlcmd -S $databaseserver -Q "ALTER DATABASE [$databasename] SET SINGLE_USER"

sqlcmd -S $databaseserver -Q "DROP DATABASE [$databasename]"

 

$databasename="MOSS_Admin_Content_01"

sqlcmd -S $databaseserver -Q "ALTER DATABASE [$databasename] SET SINGLE_USER WITH ROLLBACK IMMEDIATE"

sqlcmd -S $databaseserver -Q "ALTER DATABASE [$databasename] SET SINGLE_USER"

sqlcmd -S $databaseserver -Q "DROP DATABASE [$databasename]"

Text Generator

Often I want to generate text for web sites or just fill in the blanks…here is the coolest thing…Lorem Ipsum (http://www.lipsum.com/) and they have a simple XML service to push stuff back…

 

http://www.lipsum.com/feed/xml?amount=<int>&what=<paras,words,bytes>&start=<yes,no&gt;

    type: bytes,words,paras

    Start: yes,no (Whether to start with "Lorem ipsum dolor")

 

PowerShell Example: 

[xml]$w = (new-object net.webclient).DownloadString("http://www.lipsum.com/feed/xml?amount=10&what=paras&start=yes&quot;)

#text output is in the following

$w.feed.lipsum

File Upload with HashTable and Multie Value Columns

Was trying to upload some documents the other day using an XML file with the metadata.  I needed to split a bunch of data out and submit it to SharePoint as a list column with Multiple Values.  This, and lookup columns, you really have to understand how the data is sored in SQL first before trying to just do thls.  What I did was:
 
  • Upload a couple of items through the UI and set the values.
  • Open up SQL and run a query to find the detail:

select nvarchar10,nvarchar11,ntext2,* from alluserdata WHERE tp_LeafName = ‘Test File.txt’ order by tp_version desc

  • The columns you want to see with the values you can fine in the SPList.SchemaXml…file the Field element with the field it stores the data in
  • From here, I realized the multiple value fields are completely surrounded and split with ;#.  For example, if you have values A,B, then it would be ;#A;#B;#.

That is all, upload these files with the SPFolder.Files.Add() method and create yourself a HashTable with the metadata and you are off and running…of course this is real easy through PowerShell:

$site = new-object microsoft.sharepoint.spsite(http://server)

$web = $site.rootweb

#$list = $web.Lists["ListName"]

#$list.Schema.Xml

$folder = $web.getfolder("/ListName")

 

$x=@{}

#Plain Text Field

$x.add("Plain","Blah blah")

#Field with Choice and Checkboxes…

$x.add("MultiValue",";#A;#B;#")

$bytes=[byte[]]get-content export.csv -encoding byte

$file = $folder.files.add("Test File.txt",$bytes,$x,$true)

AJAX and Publishing Sites…DO NOT WORK

I posted this on forums after a suggestion from a person working with me from Microsoft.  I haven’t even received a bite yet.  Please post a comment if you have also had issues with AJAX and publishing sites.  I have yet to see MS post anything that says this does not work.
 
To test:
  • Create an AJAX Web Part that works in a standard BLANK site
    • Of course you have to do things like add the ASP:ScriptControl and other things to your default.master or whatever…but do it
  • Enable Publishing features (these are at the Site Collection level and the Site level)
  • I bet the AJAX will work right away…yup, but ONLY with the basic master page
  • Change the master page to something other than the one you carried over with the BLANK site…guess what…

If you have any feedback, post it on forums

ListInstance with Scope at Site ERROR

Found this out the hard way today, and found little posts that explained exactly what this does.  If you have a ListTemplate in a feature to define your list (which is Hidden) and then have a separate feature with a ListInstance inside, the ListInstance/@RootWebOnly attribute is only available when the Feature/@Scope=’Web’.  If you set the Feature/@Scope=’Site’ and have the ListInstance/@RoowWebOnly=’TRUE’, you will get the lovely "Object reference not set to an instance of an object".
 
Hope this helps someone…