Delphi Technology Solutions - development, websites, computers and networks

Development   |   Computers & Networks   |   Websites   |   Products & Services   |   Client Success   |   News

David's Ramblings on Development

SharePoint, InfoPath, .Net and more




Copy a SharePoint Site via Code

Share |
clock December 21, 2009 09:03 by author David Lozzi

I recently had to create some functionality for a customer to take a subsite, and duplicate it for backup purposes. I would normally walk them through the process using stsadm or use Save Site as Template but they wanted a simple method of doing it. I created them a on click solution.

My code is below. We were going to move forward with the SPWeb SaveAsTemplate option but the site was too large. Even after increasing the template size SharePoint still errored. See KB Article 960969 for more details. So instead we are using stsadm and exporting the site then importing it.

Exporting a Site

Process exportSite = new Process();

string commonFilesPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles);
string commandLine = " -o export -url " + SPContext.Current.Web.Url + " -filename c:\\" + tempName + ".exp -overwrite -includeusersecurity";

exportSite.StartInfo.UseShellExecute = true;
exportSite.StartInfo.FileName = commonFilesPath + @"\Microsoft Shared\web server extensions\12\BIN\" + "stsadm.exe ";
exportSite.StartInfo.Arguments = commandLine;
exportSite.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
exportSite.Start();
exportSite.Close();

Importing a Site

Process importSite = new Process();
string commonFilesPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles);
string commandLine = " -o import -url " + SPContext.Current.Web.Url + "/" + tempName + " -filename c:\\" + tempName + ".exp -includeusersecurity";

importSite.StartInfo.UseShellExecute = true;
importSite.StartInfo.FileName = commonFilesPath + @"\Microsoft Shared\web server extensions\12\BIN\" + "stsadm.exe ";
importSite.StartInfo.Arguments = commandLine;
importSite.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
importSite.Start();
importSite.Close();

Hope this helps! If you have a better method I would love to hear it, I'm always looking for ways to improve!!





Browser Size by Google

Share |
clock December 17, 2009 09:18 by author David Lozzi

Google recently published a new tool to help web designers and developers assess the real estate on their pages. It's a basic tool which overlays a standard graph over your pages showing you the percentage of visitors who have their browsers open to the specific size. Check it out at http://browsersize.googlelabs.com/.

I played around with it a bit and found it a little too elementary. Any good web designer knows that you have to stay above the fold and shouldn't exceed certain widths. If you web page is centered, the tool doesn't take that into account so it'll show that your page won't be seen by 20% of your visitors, for example, using our site on my screen at 1920x1080, their tools shows this:

Only 80% of my visitors will see half of the page. Apparantely that's not accurate. If I resize my browser to 1024x768, it's more accurate.

Now it shows that only 5% of the visitors may not see the full width. According to Google, "Browser Size works best on web pages with a fixed layout aligned to the left. If the content reflows as the width is adjusted or it is centered, then the results can be misleading. In this case, you can obtain more accurate results by reducing the browser width to a percentage column, e.g. 90% and seeing what content falls below the 90% horizontal line."

One more thing that is nice, you can specify an internal web address as well. For instance, if you are developing a site and want to check out the browser size, simply type in the internal URL and blamo you're comparing it to your internal address. It appears the window displaying the website is client based not server based.

I watch this tool with anticipation, it has potential of being a great tool. Integrating it with their Google Analytics would be REAL nice too.





Could not load file or assembly on SharePoint page

Share |
clock December 9, 2009 13:48 by author David Lozzi

As a SharePoint developer, you may be creating a web part and for the sake of testing you throw it up on your site. Then you decide to rename your class or get a new public key token for your class or something like that. After doing so, your page might stop loading with the following error.

You may not be a developer, you simply obtained a web part from another party and now it's not working and you get the following error.

An error occurred during the processing of . Could not load file or assembly 'Class.Class, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20f2595270a5ec23' or one of its dependencies. The system cannot find the file specified

If you're lucky you are running into this on your default.aspx so clicking Go back to site doesn't work. If you want the fix, scroll down to The Fix. Or read on to understand what's going on.

In my own understanding, the issue is as follows:

When you add a web part to a page the web part's associated assembly is registered in the page, i.e.:


Screen shot from SharePoint Designer.

As you can see in lines 1 and 2, there are register tags for my two web parts I have on my page. The registers call on the entire assembly of the class the web part uses, which is what the page is erroring on. Normally, if you close a web part on a page through the web interface the web part doesn't get removed from the page, it's just invisible. In SharePoint Designer (SPD) the web part appears grayed out and the register tag remains on the page. Get SharePoint Designer for free!

 

To have the web part reappear, using SPD, change the __designer:IsClosed property of the web part from true to false. Save the page and your web part is back.

So how do we properly get rid of a web part? This is not the fix to the error, this is how to prevent receiving the error in the future. Instead of just closing the web part, you need to delete it.

To do so, go to Site Actions then Edit Page. Then click the Edit menu for the web part and you'll see Delete. Click to remove the web part, and it's registered tag from the page.

You won't need to do this for resident SharePoint web parts, like views of lists and libraries. This will be necessary for any third party custom web part.

 

The Fix

On to the fix. If it's too late for you, and the web part was already closed or removed or uninstalled and you're getting this error, try these steps:

  1. Go to http://servername/_layouts/settings.aspx. This should bring you to the Site Settings page.
  2. Click Reset to site definition in the Look and Feel column.
  3. Enter the full URL to the page that is erroring.
  4. Click Reset and confirm.

This functionality resets the page entirely so if you have any customizations on the page itself, it will remove them all. It does not appear however to remove other custom web parts that are installed.

I hope this helps!




RSSRSS Subscribe

About David Lozzi

I love what I do. I'm not the sketchy type that hides in his basement coding all day. I have a beautiful wife and two great children. I've spent my last 10 years plus in the technology arena. more...

Login