General Bloging

Development and Stuff

About the author

Author Name is someone.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Changing list ID for a customised page

Once you have customised a page in Sharepoint designer using data views the list id etc are embeded into the page.

If you the export and import the site, all id become invalid, the code below is how to restamp the customised page with the new Id. 

try

{

//using (SPSite site = new SPSite(SPContext.Current.Site.ID))

using (SPSite site = new SPSite(SiteURL))

{

using (SPWeb Web = site.OpenWeb(WebURL))

{

//This bit of code restamps all the list guid that SPD

//put into the page source for our customised project home page.

//When the site is exported and re-imported all lists get new ID hence the page is

//broken this fixes it for the new site.

byte [] bfile = Web.Files["default.aspx"].OpenBinary();

System.Text.Encoding enc = System.Text.Encoding.ASCII;

string myString = enc.GetString(bfile);

//re-stamp the guids from the default projector site with the new ones that

//have been created in this site.

SPList list = Web.Lists["List Name"];

myString = myString.Replace("69D01208-49F1-43BC-ABF9-550A75BD1A54", list.ID.ToString());

bfile = enc.GetBytes(myString.Replace("???",""));

Web.Files["default.aspx"].SaveBinary(bfile);Web.Files[

"default.aspx"].Update();

 

}

catch (Exception ex)

{

Console.WriteLine("Exception " + ex.ToString());

}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Simran
Posted by gurney on Monday, March 10, 2008 8:10 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Related posts

Comments

simran gb

Monday, March 10, 2008 8:19 PM

simran

YOU DIDDNT HAVE ANY TEXT IN THIS.
DUDEEE!
=D

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Saturday, May 10, 2008 1:25 AM