Tuesday, January 11, 2011
SPWeb GetList Exception from HRESULT: 0x80070003 System.IO.DirectoryNotFoundException
All you need to provide is a site-relative URL like the following
"/sites/myWeb/Lists/myCoolList".
If you are in the top-lelel site collection and wondering what the heck , then it should be like "/Lists/myCoolList"
"Unhandled Exception: System.IO.DirectoryNotFoundException: The system cannot find the path specified. (Exception from HRESULT: 0x80070003)"
Deleting Document Library Items for large list size Failed?
The maximum items that your program can delete is 25000 which can be changed.
Hey friends, If you have saved lot of time using my code, please pay me by smiling at all the people you see today. They will smile back at you. We will all be in a pool of happy smiles. If you have a big wallet, feed a hungry stomach today. And God will bless you.
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
StringBuilder sbDelete = new StringBuilder();
SPList spList = web.GetList("/" + listName);
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
"</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar><SetVar Name=\"owsfileref\">{1}</SetVar></Method>";
int limit = 0;
foreach (SPListItem item in spList.Items)
{
limit++;
if (limit > 25000)
break;
sbDelete.Append(string.Format(command, item.ID.ToString(), item.File.Url));
}
sbDelete.Append("</Batch>");
web.ProcessBatchData(sbDelete.ToString());
web.Update();
web.AllowUnsafeUpdates = false;
}
}
Deleting ListItems for large list size Failed?
For novice to use this code, specify the strings variables siteURL, listName.
The maximum items that your program can delete is 5000 which can be changed.
The way web.Lists[listName] works is that it loads the meta-data information of the all lists for that specific SPWeb object and then it does SPList.Title comparison with metadata of all the lists returned and returns the first matching list from the SPWeb.Lists collection. This has got two implications:
1. The loading of list is slow as the meta-data information of all the list is loaded and then comparison happens on list name specified.
2. If there are large numbers of lists in a specific SPWeb, the process of getting the meta-data information of all the available lists may introduce transaction lock in backend database when multiple such calls happen in quick succession.
The suggested way to access a list is by using SPWeb.GetList(string url). In this case, first the GUID of list is figured out and then meta-data for the list is loaded. Obviously, this is a faster way also.
If your head is already spinning, the summary is that
"And you must use web.GetList(listName) instead of web.Lists[listName]. Otherwise it may take for ever."
Hey friends, If you have saved lot of time using my code, please pay me by smiling at all the people you see today. They will smile back at you. We will all be in a pool of happy smiles. If you have a big wallet, find & feed a hungry stomach today(not mine). And God will bless you.
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
StringBuilder sbDelete = new StringBuilder();
SPList spList = web.GetList("/Lists/" + listName);
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
string command = "<Method><SetList Scope=\"Request\">" + spList.ID +
"</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
int limit = 0;
foreach (SPListItem item in spList.Items)
{
limit++;
if (limit > 5000)
break;
sbDelete.Append(string.Format(command, item.ID.ToString()));
}
sbDelete.Append("</Batch>");
web.ProcessBatchData(sbDelete.ToString());
web.Update();
web.AllowUnsafeUpdates = false;
}
}
Wednesday, December 29, 2010
SharaPoint CAML OrderBy DefaultView Limit
Thursday, November 18, 2010
Truncate and shrink Transaction Log file in SQL Server 2008
In SQL Server this process have been changed. In 2008, just change the recovery model to simple and then use DBCC Shrinkfile command.
use [YourDatabaseName]
select name,recovery_model_desc from sys.databases
GO
Alter database [YourDatabaseName] Set Recovery SIMPLE
GO
Declare @LogFileLogicalName sysname
select @LogFileLogicalName=Name from sys.database_files where Type=1
print @LogFileLogicalName
DBCC Shrinkfile(@LogFileLogicalName,1)
______________________________
If you may want to set the recovery back to Full. If so, add the following.
Alter database [YourDatabaseName] Set Recovery FULL
Thursday, May 27, 2010
XSLT String Padding
<xsl:template name="leftjustify">
<xsl:param name="content"/>
<xsl:param name="width"/>
<xsl:choose>
<xsl:when test="string-length($content) > $width">
<xsl:value-of select="substring($content,1,$width)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$content"/>
<xsl:call-template name="spaces">
<xsl:with-param name="length">
<xsl:value-of select="$width - string-length($content)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="spaces">
<xsl:param name="length"/>
<!-- the value of this next variable is 255 spaces.. -->
<xsl:variable name="longstringofspaces">
<xsl:text> </xsl:text>
</xsl:variable>
<xsl:value-of select="substring($longstringofspaces,1,$length)"/>
</xsl:template>
Usage:
<xsl:call-template name="leftjustify">
<xsl:with-param name="content">You can do this</xsl:with-param>
<xsl:with-param name="width">40</xsl:with-param>
</xsl:call-template>
Tuesday, July 7, 2009
InfoPath 2007 Template Parts
The InfoPath 2007 was released and it has a new feature called Template Parts. Template Parts is a new type of InfoPath template that allows for predefined forms to be saved and then imported into the InfoPath Controls Task Pane. A Template Part is capable of saving Data Connections, Rules, Conditional Formatting, Data Validation and many other things. Just having this capability has saved me a tremendous amount of time when designing forms and it has increased the ROI for the client. A standard address block is one of the first things that I create for a new client because I'm able reuse it right away and show immediate ROI. At first you might not think this would have a big impact but when you take in account that, you no longer have to worry about defining the data source fields, layout table, field widths, colors, font style/size, data connections for states/regions and country, data validation, rules or conditional formatting then the ROI is reached pretty quickly. Once I understood this capability it changed how I started developing forms.
A feature of a Template Part that you need to take in consideration when using them to help designing forms is the Update capability. The Update capability allows for existing Template Part control on a form to be updated once the master Template Part control has changed and re-imported into the designer. At first this capability was frustrating because I didn't design everything with this in mind but after understanding how it worked, I quickly changed how I was designing forms and took advantage of the Update capability.
Long story short, Template Parts are great if you put thought into how you are building and using them. If you don't do this then it will just adds more complexity when building your InfoPath form and shouldn't be used.