Browse by Tags

All Tags » C# (RSS)

Impersonating a Built-in Service Account in a Console Application

Here's a quick way to impersonate a built-in service account (NT AUTHORITY\NETWORK SERVICE or NT AUTHORITY\LOCAL SERVICE) or for that matter the Local System account (NT AUTHORITY\SYSTEM) in a console application. This might be useful for debugging Read More......( read more ) Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks
Posted by SharePoint Blogs
Filed under: ,

Delete SharePoint Document Library Files Programmatically

Following on from this post on moving or copying SharePoint files with FrontPage Remote Procedure Calls (RPC), and this older post on remotely saving files to a SharePoint document library, the code below demonstrates how to remove files programmatically Read More......( read more ) Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks
Posted by SharePoint Blogs
Filed under: , ,

Move SharePoint Document Library Files Programmatically

In this post I published some code that took a look at using FrontPage Server Extentions to upload a file to a document library where the requirement was to be able to save metadata along with the document and not use the API. Here are a few more static Read More......( read more ) Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks
Posted by SharePoint Blogs
Filed under: , ,

SharePoint Connections - The Real Day 2

I started off by trying out Veli-Matti Vanamo's Introduction to Web Part Development presentation. He was actually a substitute for his co-worker, Emer McKenna. The majority of the content was from their new book to be released in Dec, Microsoft SharePoint 2007 Technologies: Planning, Design and Implementation . While the majority of the presentation was slide deck, there was still some good information to be had there. A few notes from this session I took were as follows: Web part management is almost identical between SharePoint and ASP.Net 2.0. The two primary differences are that in SharePoint, you can add the Microsoft.SharePoint.dll reference to get additional functionality, and when using SharePoint, the webpartmanager is overridden by the spwebpartmanager, to apply SharePoint specific details to the rendering. There are three acceptable types of web parts: The ASP.Net 2.0 Web part, which uses the System.Web.dll for it's inheritance, and is compatibility with both ASP.Net Web Part Zones, and SharePoint/WSS 3.0 Web Part Zones. These web parts are usually labeled with a .webpart extension. The WSS 2.0 web part, which uses the Microsoft.SharePoint.dll library for its inheritance, and is a deprecated method for creating web parts. The compatibility is still there for moving web parts from WSS 2.0 to WSS 3.0. These web parts have a .dwp extension. The Hybrid web part, which uses both the above mentioned dll libraries for inheritance, and is specific to WSS 3.0/MOSS....
Posted by SharePoint Blogs

Problem with Custom Web Part! Big issue!

Ok, so I can use this web part and it adds to the list just fine, but when my colleague with the same permissions to the list uses it, she can't get it to add to the list.... I implemented the run with elevated priviledges and used guids instead of using the spcontext.current(heard that negates the elevated priviledges) Any thoughts? private void PopulateDataset() { try { mySite = new SPSite(siteURL); try { myWeb = mySite.OpenWeb(parentURL); } catch { myWeb = mySite.RootWeb; } favList = myWeb.Lists[listName]; NAPWS.Service napService = new global::WPRecordSiteVisits.NAPWS.Service(); oDataSet = napService.SearchClients(); oView.Table = oDataSet.Tables[0]; } catch(Exception e){ lblError.Text += "| PopulateDataSet: " + e.Message; } } private void RecordSiteVisits() { try{ if ((HttpContext.Current.Request.UrlReferrer == null || HttpContext.Current.Request.UrlReferrer.AbsoluteUri.IndexOf(SPContext.Current.Web.Url) == -1) && (HttpContext.Current.Session["Referrer"] == null || HttpContext.Current.Session["Referrer"].ToString().IndexOf(SPContext.Current.Web.Url) == -1)) { if (HttpContext.Current.Session["Referrer"] != null) HttpContext.Current.Session["Referrer"] = SPContext.Current.Web.Url; string pathString = HttpContext.Current.Request.Url.AbsolutePath.ToString(); string strNC_Number = ""; if (pathString.IndexOf("NAP/") != -1) { pathString = pathString.Substring((pathString.IndexOf("NAP/") ...

SharePoint Pro Online Live Event Today!

Wow, this event was extraordinarily useful! From Document Management and Office integration to Features Building and AJAX Web Parts. They had it covered. Very impressive. If you are interested in MOSS 2007 at any level you should check out the recorded sessions at http://events.unisfair.com/rt/sharepoint~oct07 . Posted on SharePoint Blogs Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Discussion: Custom Field Controls vs. Custom Web Parts

I watched a video with Andrew Connell, and it was brought to my attention that Custom Field Controls may be more appropriate than custom web parts in certain situations... One question that I have is if the tool pane is accessible for the end user when dealing with a field control... Can the design set configuration data from sharepoint designer? Please post any thoughts you may have. Posted on SharePoint Blogs Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Custom Web Part Building: State Management Tips and Tricks

When building custom web parts its essential to understand when controls will contain thier values and when they don't and how to keep variables that will contain their values throughout the web part life cycle. Especially if you would like to dynamically load one control based on another controls input. 1. In CreateChildControls, No control will contain a value, not even hidden fields. This eliminates some uses of a common practice of utilizing hidden field to maintain viewstate. 2. ViewState Parameters are great for maintaining values throughout the web part lifecycle. Initialize them in the constructor of a web part to avoid null errors. Initializing a view state parameter: ViewState["parameter1"] = ""; Retrieving a value from view state: string this = ViewState["parameter1"].toString(); 3. If you would like to maintain a web parts state while navigation persists in your website, you can utilize session state variables with the following code: Adding a variable to session state: HttpContext.Current.Session.Add("variablename1", "value1"); Retrieving a variable from session state: writer.Write("'" + HttpContext.Current.Session["variablename1"] + "'"); Posted on SharePoint Blogs Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Custom Web Part Code: Adding the default doc lib menu to a custom web part

So I found a way to add the default drop down menu to the items of a custom web part control. Its pretty convoluted, so if you form a more direct way let me know. See code below: This Template is needed to be instantiated, but we don't render it... (lil trick) msaListMenu = new MenuTemplate(); msaListMenu.ID = "DocLibMenu"; I use this menu column to expose multiples values I need for the menu: SPMenuField msaColMenu = new SPMenuField(); msaColMenu.HeaderText = "Name"; msaColMenu.TextFields = "FileLeafRef, ID, COUID"; //msaColMenu.TextFormat = "{0}/{1}/{2}"; msaColMenu.MenuTemplateId = "DocLibMenu"; //msaColMenu. msaColMenu.NavigateUrlFields = "FileLeafRef";//Client_x0020_Name_x0020_2"; msaColMenu.NavigateUrlFormat = SPContext.Current.Web.Url+"/[Doc Library Name]/1/{0}";//1 msaColMenu.TokenNameAndValueFields = "EDIT=ID,NAME=Title,TYPE=DocIcon,REF=FileLeafRef"; msaColMenu.SortExpression = "Title"; msaGrid.Columns.Add(msaColMenu); Javascript I implanted directly after the rendering of the SPGridView Control (this javascript manipulates the menu field that we put in our SPGridView control and gives it the identical html that the default web parts use for their menus: string transplantMenuFunction = ""; transplantMenuFunction += "<script>\n"; transplantMenuFunction += "function transplantMenu(){\n"; transplantMenuFunction += " var error;\n";...

Custom Web Part Code: Deleting an Item

So this works, but if anyone has any brighter ideas, I have open ears... I was creating a document library web part and had to recreate some of the functionality in the menu... So here is the way I delete and Item... Declare and initialize a hidden field to store the id of the element to be deleted... hfDeleteDoc //Server Side Function (C#) private Boolean deleteDoc(int ID){ try { if (msaListName != null && msaListName != "") { SPContext.Current.Web.Lists[msaListName].Items.DeleteItemById(ID); } return true; } catch { return false; } } //Server Side Code (C#) if (hfDeleteDoc.Value != "") { int id = Convert.ToInt32(hfDeleteDoc.Value); deleteDoc(id); hfDeleteDoc.Value = ""; } //Server Side Code (C#) Building a javascript function for your menutemplate string deleteDocFunction = ""; deleteDocFunction += "<script>\n"; deleteDocFunction += "function deleteDoc(docID){\n"; deleteDocFunction += " var hfDeleteDoc = document.getElementById('" + hfDeleteDoc.ClientID + "');\n"; deleteDocFunction += " hfDeleteDoc.value = docID;\n"; deleteDocFunction += " document.forms[0].submit();\n"; deleteDocFunction += "}\n"; deleteDocFunction += "</script>\n"; writer.Write(deleteDocFunction); //Server Side Code (C#) Creating a template for your menu msaListMenu = new MenuTemplate(); msaListMenu.ID = "MSAListMenu"; MenuItemTemplate msaListMenuItem1...

MOSS 2007: Is collaboration for everyone?

I met with the SharePoint Users Group of Kansas City today. And they brought up an interesting topic. And all in all it makes sense. Should IT release SharePoint in the hands of the end users... I would say yes, but your managers and execs would probably say no. Like the mindsharp people were saying SharePoint is a tool for their employees to communicate with other employees... and everytime you attempt to increase the communication in the workplace there is hesitation by management. The oldest MCT in the biz, a mindsharp trainer, was recalling the days when companies were first thinking about placing phones at employees desks... and then when email was to hit the desktop with Outlook... Each time a tool becomes available to enhance communication among employees, management wants to have their hands in it, with an attempt to control and police it. However, like with email and the phone, SharePoint will produce more results when it is placed in the hands of the employees. Each individual employee having their own mysite, and each dept having its own site with subsites. There will be a learning curve, but someday it will be an everyday utility. There is also another side to SharePoint, a development environment for web based applications. Also SharePoint can be used as a WUI, web user interface, (Intranet) for various web applications you already have in place, or develop new Web Part centric applications. Your applications, now housed in SharePoint, will inherit SharePoint's...

Discussion: Site versus Web in MOSS 2007

I would like to open this discussion up because I'm having trouble differentiating the terms. Especially when dealing with the object model. SPSite vs. SPWeb. Are there any known differences? My latest thoughts have been that SPSite is the top level site for a site collection and SPWeb can be a site within that site collection... But very unsure here. Please comment! Posted on SharePoint Blogs Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Adding content to Word "content control" programmatically

Category: Word programming Level: Advance Here is a small tip on how to add data to Word content control programmatically. If you don't know what are content controls, you can read about them at the following sites: http://blogs.msdn.com/microsoft_office_word/archive/2006/10/23/control-yourself.aspx http://blogs.msdn.com/modonovan/archive/2006/05/23/604704.aspx http://blogs.msdn.com/erikaehrli/archive/2006/08/11/word2007DataDocumentGenerationPart1.aspx http://msdn2.microsoft.com/en-us/library...( read more ) Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Dynamic Site intergrated with a Database, List, or BDC Data

Use web parts that either actions(BDC Data), custom columns(List), or spgridview control(Database), to establish links that provide a query variable to your dynamic page. On your dynamic page, create a web part or embed server side code that creates a folder in each of your lists, document libraries, or wikki libraries. Make sure that these folder are also assigned an id value to an id field(only can be do programmatically, no default UI for this). Use the query variable given to arrange for a rootfolder query variable that navigates list web parts to their respective folders. Modify any extraneous links through javascript, utilize cookies and redirects with a custom web part to hold id values despite application page navigation. Well, I hope this helps, and good luck in the world of sharepoint! Posted on SharePoint Blogs Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

My First SharePoint Blog

Hey all, I am an IT Consultant with Levi, Ray, and Shoup, Inc. I attended their Portal University in July - October '05 and have worked with LRS as a SharePoint Consultant ever since. I have been on numerous successful engagements deploying SharePoint 2003, MOSS 2007, InfoPath 2003 and 2007. I have a strong foundation in many languages including but not limited to SQL, C#, XML, XSLT, JavaScript, CSS, HTML, ASP.NET. I have worked with SharePoint...