WSS 3.0 does not have a mechanism for tracking who downloads which files with authenticated users. When I got confronted with this task, I decided to create a web user control that reads all the files in a document library and subsequently displays the file names using a series of "LinkButton" controls. I then attached this web user control to a SharePoint WSS 3.0 web page. I decided against using a Hyperlink object in favor of a LinkButton ASP.NET control for the following two reasons:
1) With a HyperLink ASP.NET control, users can right-click on the anchor and choose "Save target as" to save the file. This is not desirable because no event is triggered when that happens. On the other hand, a LinkButton control does not produce a right-click popup in a browser leaving the user with no choice but to click on the link.
2) I needed to put some business logic behind the click event of the LinkButton. The business logic essentially saves statistics along the lines of: timestamp, host address, user ID, and filename.
Wednesday, November 26, 2008
Wednesday, October 22, 2008
How to programatically delete a SharePoint 2007 field belonging to a list or document library?
Here's the code for deleting a field named "phone" in list "myList" on a site with URL http://mysite/:
try {
using (SPSite sitecollection = new SPSite("http://mysite/")) {
using (SPWeb web = sitecollection.OpenWeb()) {
web.AllowUnsafeUpdates = true;
// Delete Sharepoint SPField
web.Lists["myList"].Fields.Delete("phone");
web.Update();
Console.WriteLine("Done deleting column");
}
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
try {
using (SPSite sitecollection = new SPSite("http://mysite/")) {
using (SPWeb web = sitecollection.OpenWeb()) {
web.AllowUnsafeUpdates = true;
// Delete Sharepoint SPField
web.Lists["myList"].Fields.Delete("phone");
web.Update();
Console.WriteLine("Done deleting column");
}
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
Tuesday, October 21, 2008
How do you break up a long SharePoint 2007 survey?
What do you do if you have a long SharePoint 2007 survey and you want to break it up into separate pages such that the user needs to click the "Next" button?
Solution:
You must use branching on selected questions for this. All branching items would simply point to the next question. That produces a “Next” button.
Solution:
You must use branching on selected questions for this. All branching items would simply point to the next question. That produces a “Next” button.
Thursday, July 24, 2008
How to use built-in SharePoint 2007 engine to send email?
A straightforward way of sending email from within a SharePoint 2007 application is to use the Object Model. Here is some C# code that will do it for you:
bool isAppendHtmlTag = true;
bool isHtmlEncode = false;
string recipient = "whoever@whatever.com";
string title = "This is the title";
string body = "This is the email <strong>body</strong>";
Microsoft.SharePoint.Utilities.SPUtility.SendEmail(
Microsoft.SharePoint.SPContext.Current.Web,
isAppendHtmlTag,
isHtmlEncode,
recipient,title,
body);
bool isAppendHtmlTag = true;
bool isHtmlEncode = false;
string recipient = "whoever@whatever.com";
string title = "This is the title";
string body = "This is the email <strong>body</strong>";
Microsoft.SharePoint.Utilities.SPUtility.SendEmail(
Microsoft.SharePoint.SPContext.Current.Web,
isAppendHtmlTag,
isHtmlEncode,
recipient,title,
body);
Sunday, July 20, 2008
Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.
Recently I noticed that many of my ASP.NET applications that work with a SQL Server Express database that resides in the App_Data directory stopped working. The culprit error was "Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances.". I suspect that a SQL Server update went out that disables user instances. I have not been able to substantiate this suspicion yet.
SOLUTION:
The solution is to enable user instances with the following command:
sp_configure 'user instances enabled','1';
Disable user instances with the following command:
sp_configure 'user instances enabled','0';
SOLUTION:
The solution is to enable user instances with the following command:
sp_configure 'user instances enabled','1';
Disable user instances with the following command:
sp_configure 'user instances enabled','0';
Friday, July 18, 2008
How to change the connection string name in a .NET 3.5 LINQ to SQL class?
Here's the scenario:
You developed an application that uses "LINQ to SQL" with a connection string name (say aa-db). In production you want the name to be different (say bb-db). What do you need to do to change the connection string name?
1) Open the *.dbml file in a text editor.
2) Change the "SettingsPropertyName=" property to the new name
3) Open the "*.designer.cs" file that is associated with the LINQ class and change the value of global::System.Configuration.ConfigurationManager.ConnectionStrings[...].
You developed an application that uses "LINQ to SQL" with a connection string name (say aa-db). In production you want the name to be different (say bb-db). What do you need to do to change the connection string name?
1) Open the *.dbml file in a text editor.
2) Change the "SettingsPropertyName=" property to the new name
3) Open the "*.designer.cs" file that is associated with the LINQ class and change the value of global::System.Configuration.ConfigurationManager.ConnectionStrings[...].
How to edit group on the SharePoint quicklaunch in WSS 3.0 (and MOSS 2007)?
It is always a good idea to lock down SharePoint sites such that users do not see more information than they need to. At the organization where I work, we have a plethora of SharePoint groups. With any new website that gets created, a user with full rights gets to see a list of all the groups by going to "Site Actions / Site Settings / Advanced Permissions". There is always the danger that a user can inadvertently delete or add a user to the wrong group. One simple solution is to remove unneeded groups from the quicklaunch. Here's what you can do:
- Click on Site Actions / Site Settings / Advanced Permissions
- Click on any group on the quicklaunch under "Groups"
- Click on Settings / Edit Group Quick Launch
- On the "Edit Group Quick Launch" page, highlight any group and hit the delete key on your keyboard
Subscribe to:
Posts (Atom)