Recently I got a request from a client to get a report of the number of items they had in the document libraries on their site. They wanted it broken down with the number of files per site, document library, and eventually per folder. Anyways its a fairly simple procedure (or so I think anyways), but figured I’d post it up since its been a while since I’ve thrown anything up. The code is broken into two methods, the first is used to iterate through all the child webs of a given SPWeb and also iterates through all the lists for that web and then calls the second method to interate through all the folders in a given list.
public void CrawlWeb(SPWeb web)
{
foreach (SPList list in web.Lists)
{
CrawlFolder(list.RootFolder);
}
foreach (SPWeb subWeb in web.Webs)
{
CrawlWeb(subWeb);
}
}
public void CrawlFolder(SPFolder folder)
{
if (folder != null && folder.Name.CompareTo(“forms”) != 0)
{
foreach (SPFolder subFolder in folder.SubFolders)
{
CrawlFolder(subFolder);
}
}
}
Tuesday, March 31, 2009
Tuesday, March 17, 2009
adding a new menu Item in Sharepoint. (SharePoint Features)
WSS 3.0 - How to create new SharePoint Feature?
How to create New Feature in WSS 3.0? / MOSS 2007
How to add new menu item under “Site Settings” menu in wss 3.0?
1. Create a new folder, called “SabinsNewFeature”, in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
2. Create an Xml file, called “feature.xml” in the “MyListUserFeature” folder
3. Edit the feature.xml file and add the following content
Title="Feature My List User Feature"
Description="Custom action on Site Actions"
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
4. Replace the GUID placeholder in the previous Id attribute, generate a GUID by running guidgen.exe, located in Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools.
Create an Xml file, called “ListUsers.xml” in the “SabinsNewFeature” folder
5. Edit the file and add the following content
GroupId = "SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="List Users">
6. Install the new feature by running the following command by going to Start>Run>cmd
change to the following directory: %COMMONPROGRAMFILES%\Microsoft shared\Web server extensions\12\Bin. (Because, STSADM.EXE sits in this folder )
Execute the following command from the above location
Stsadm –o installfeature –filename SabinsNewFeature\feature.xml
You will get a message saying "Operation completed Successfully"
7. Activate the new feature by running the following command
stsadm –o activatefeature -filename SabinsNewFeature\feature.xml -url http://siteurl
if your site has been in the port,
stsadm –o activatefeature -filename SabinsNewFeature\feature.xml -url http://siteul:port number
Now you will see the new menu item in the "Site Settings" of the site that you installed the feature.
How to create New Feature in WSS 3.0? / MOSS 2007
How to add new menu item under “Site Settings” menu in wss 3.0?
1. Create a new folder, called “SabinsNewFeature”, in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
2. Create an Xml file, called “feature.xml” in the “MyListUserFeature” folder
3. Edit the feature.xml file and add the following content
Description="Custom action on Site Actions"
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
4. Replace the GUID placeholder in the previous Id attribute, generate a GUID by running guidgen.exe, located in Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools.
Create an Xml file, called “ListUsers.xml” in the “SabinsNewFeature” folder
5. Edit the file and add the following content
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="List Users">
6. Install the new feature by running the following command by going to Start>Run>cmd
change to the following directory: %COMMONPROGRAMFILES%\Microsoft shared\Web server extensions\12\Bin. (Because, STSADM.EXE sits in this folder )
Execute the following command from the above location
Stsadm –o installfeature –filename SabinsNewFeature\feature.xml
You will get a message saying "Operation completed Successfully"
7. Activate the new feature by running the following command
stsadm –o activatefeature -filename SabinsNewFeature\feature.xml -url http://siteurl
if your site has been in the port,
stsadm –o activatefeature -filename SabinsNewFeature\feature.xml -url http://siteul:port number
Now you will see the new menu item in the "Site Settings" of the site that you installed the feature.
Wednesday, March 4, 2009
SQL Server: "Cannot open user default database" Error 4064
SQL Server 2005
You can use the sqlcmd utility to change the default database in SQL Server 2005. To do this, follow these steps:
Click Start, click Run, type cmd, and then press ENTER.
Use one of the following methods, depending on the kind of authentication that the SQL Server login uses:
If the SQL Server login uses Microsoft Windows authentication to connect to the instance, type the following at the command prompt, and then press ENTER:
sqlcmd –E -S InstanceName –d master
If the SQL Server login uses SQL Server authentication to connect to the instance, type the following at the command prompt, and then press ENTER:
sqlcmd -S InstanceName -d master -U SQLLogin -P Password
Note InstanceName is a placeholder for the name of the SQL Server 2005 instance to which you are connecting. SQLLogin is a placeholder for the SQL Server login whose default database has been dropped. Password is a placeholder for the SQL Server login password.
At the sqlcmd prompt, type the following, and then press ENTER:
ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName
Note AvailDBName is a placeholder for the name of the existing database that can be accessed by the SQL Server login in the instance.
At the sqlcmd prompt, type GO, and then press ENTER.
You can use the sqlcmd utility to change the default database in SQL Server 2005. To do this, follow these steps:
Click Start, click Run, type cmd, and then press ENTER.
Use one of the following methods, depending on the kind of authentication that the SQL Server login uses:
If the SQL Server login uses Microsoft Windows authentication to connect to the instance, type the following at the command prompt, and then press ENTER:
sqlcmd –E -S InstanceName –d master
If the SQL Server login uses SQL Server authentication to connect to the instance, type the following at the command prompt, and then press ENTER:
sqlcmd -S InstanceName -d master -U SQLLogin -P Password
Note InstanceName is a placeholder for the name of the SQL Server 2005 instance to which you are connecting. SQLLogin is a placeholder for the SQL Server login whose default database has been dropped. Password is a placeholder for the SQL Server login password.
At the sqlcmd prompt, type the following, and then press ENTER:
ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName
Note AvailDBName is a placeholder for the name of the existing database that can be accessed by the SQL Server login in the instance.
At the sqlcmd prompt, type GO, and then press ENTER.
Tuesday, March 3, 2009
Enable remote connections to the SQL Server 2005 instance that hosts the report server database
Click Start, point to Programs, point to Microsoft SQL Server 2005,
oint to Configuration Tools, and click SQL Server Surface Area Configuration Tool.
Click Surface Area Configuration for Services and Connections.
Open the folder for the SQL Server instance that hosts the report server databases.
Click 'Remote Connections' under 'Database Engine'
Click Local and Remote Connections.
Click Using both TCP/IP and named pipes.
Click OK, and then restart the service by selecting "service" and clicking the "Stop" button at the right pane.
click "Start" button after stoping it.
oint to Configuration Tools, and click SQL Server Surface Area Configuration Tool.
Click Surface Area Configuration for Services and Connections.
Open the folder for the SQL Server instance that hosts the report server databases.
Click 'Remote Connections' under 'Database Engine'
Click Local and Remote Connections.
Click Using both TCP/IP and named pipes.
Click OK, and then restart the service by selecting "service" and clicking the "Stop" button at the right pane.
click "Start" button after stoping it.
Monday, January 19, 2009
Adding dynamic hyperlinks in the Report Viewer; ASP.Net Reports
Adding dynamic hyperlinks in the Report Viewer; ASP.Net Reports
Type the text to be displayed as the Hyperlink in the cell of your Table control added in the RDLC file. Right click on the Hyperlink text cell and click 'Navigation' tab.
Click Jump to URL radio button and add expression by clicking 'fx' button.
=iif(1<>0, Parameters!MyLink.Value+"?qBTchId=" & Fields!BatchID.Value, "")
Report Parameters can be sent from the code behind file as
Microsoft.Reporting.WebForms.ReportParameter RptLink1 = new Microsoft.Reporting.WebForms.ReportParameter("AssignLink", UriBuilder.BuildUrlNew(@"../Training/FrmAssignTraining.aspx"));
Microsoft.Reporting.WebForms.ReportParameter RptLink2 = new Microsoft.Reporting.WebForms.ReportParameter("UpdateLink", UriBuilder.BuildUrlNew(@"../Training/FrmTrainingUpdate.aspx"));
Microsoft.Reporting.WebForms.ReportParameter RptLink3 = new Microsoft.Reporting.WebForms.ReportParameter("PrintLink", UriBuilder.BuildUrlNew(@"../Training/FrmTrainingPrint.aspx"));
RptTraining.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { RptLink1, RptLink2, RptLink3 });
RptTraining.LocalReport.EnableHyperlinks = true;
=iif(1<>0,Fields!Status.Value, "")
Type the text to be displayed as the Hyperlink in the cell of your Table control added in the RDLC file. Right click on the Hyperlink text cell and click 'Navigation' tab.
Click Jump to URL radio button and add expression by clicking 'fx' button.
=iif(1<>0, Parameters!MyLink.Value+"?qBTchId=" & Fields!BatchID.Value, "")
Report Parameters can be sent from the code behind file as
Microsoft.Reporting.WebForms.ReportParameter RptLink1 = new Microsoft.Reporting.WebForms.ReportParameter("AssignLink", UriBuilder.BuildUrlNew(@"../Training/FrmAssignTraining.aspx"));
Microsoft.Reporting.WebForms.ReportParameter RptLink2 = new Microsoft.Reporting.WebForms.ReportParameter("UpdateLink", UriBuilder.BuildUrlNew(@"../Training/FrmTrainingUpdate.aspx"));
Microsoft.Reporting.WebForms.ReportParameter RptLink3 = new Microsoft.Reporting.WebForms.ReportParameter("PrintLink", UriBuilder.BuildUrlNew(@"../Training/FrmTrainingPrint.aspx"));
RptTraining.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { RptLink1, RptLink2, RptLink3 });
RptTraining.LocalReport.EnableHyperlinks = true;
=iif(1<>0,Fields!Status.Value, "")
******************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
///
/// The common class for building the URL for the report. Eg: UriBuilder.BuilUri("FrmAdvance.aspx");
///
public class UriBuilder
{
public UriBuilder()
{
//
// TODO: Add constructor logic here
//
}
///
/// This method Builds the physical Url with the page name provided
///
/// The name of the page
/// The URL string
public static string BuildUrl(string pageName)
{
Uri uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
Uri newUri = new Uri(uri, pageName);
return newUri.AbsoluteUri;
}
public static string BuildUrlNew(string pageName)
{
Uri uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri.Replace("/FeedBackQuality", ""));
Uri uri2 = new Uri(
Uri newUri = new Uri(uri, pageName);
return newUri.AbsoluteUri;
}
}
Report viewer; changing the cell background color dynamically
Report viewer; how to change the cell background color dynamically?
Select the cell which has to be colored, and press 'f4' key to get the 'properties' window of Visual Studio IDE. Go to 'BackgroundColor' property and click the '' under the dropdown list.
Just give a condition for your entity property.
=iif(Fields!TotalPrice.Value = "2500", "DarkGray", "")
Select the cell which has to be colored, and press 'f4' key to get the 'properties' window of Visual Studio IDE. Go to 'BackgroundColor' property and click the '
Just give a condition for your entity property.
=iif(Fields!TotalPrice.Value = "2500", "DarkGray", "")
Wednesday, December 3, 2008
Invoking "Save as PDF" method of Report Viewer
UserEntryFormEntity oEnt= new UserEntryFormEntity();
List oEntity = new List();
oEnt = GetReportData(JoinersId); // Method Which returns a List of Data
oEntity.Add(oEnt);
Microsoft.Reporting.WebForms.LocalReport localReport = new Microsoft.Reporting.WebForms.LocalReport();
localReport.ReportPath = Server.MapPath("~/DocumentTemplates/UserEntryForm.rdlc");
Microsoft.Reporting.WebForms.ReportDataSource oDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("UserEntryFormEntity", oEntity);
localReport.DataSources.Add(oDataSource);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo = "" + " PDF " + " 8.5in " + " 11in " + " 0.5in " + " 1in " + " 1in " + " 0.5in " + " ";
Microsoft.Reporting.WebForms.Warning[] warnings;
//Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
//Clear the response stream and write the bytes to the outputstream
//Set content-disposition to "attachment" so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
List
oEnt = GetReportData(JoinersId); // Method Which returns a List of Data
oEntity.Add(oEnt);
Microsoft.Reporting.WebForms.LocalReport localReport = new Microsoft.Reporting.WebForms.LocalReport();
localReport.ReportPath = Server.MapPath("~/DocumentTemplates/UserEntryForm.rdlc");
Microsoft.Reporting.WebForms.ReportDataSource oDataSource = new Microsoft.Reporting.WebForms.ReportDataSource("UserEntryFormEntity", oEntity);
localReport.DataSources.Add(oDataSource);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo = "
Microsoft.Reporting.WebForms.Warning[] warnings;
//Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
//Clear the response stream and write the bytes to the outputstream
//Set content-disposition to "attachment" so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
Subscribe to:
Posts (Atom)