Archive

Archive for the ‘c#’ Category

Custom UserProfile Property Class for SharePoint

June 25th, 2017 Michael Bell 3 comments

I had a recent project where I needed to bind to the properties in the sharepoint userprofile collection. I found the easiest method was to create an object that contains properties that use the PropertyConstant enumerator to return values from the UserProfile object. It may not be the cleanest, but it let me bind a list of these to a grid, which was what I needed to do.

[Serializable]
 public class UserProfilePropertyObject
 {
 private UserProfile _userProfile = null;

 public UserProfilePropertyObject(UserProfile userProfile)
 {
 _userProfile = userProfile;
 }

 public string FullName
 {
 get { return LastName + ", " + FirstName; }
 }
 public string AccountName
 {
 get
 {
 return (_userProfile[PropertyConstants.AccountName].Value ?? "N/A").ToString();
 }
 }
 public string FirstName
 {
 get
 {
 return (_userProfile[PropertyConstants.FirstName].Value ?? "N/A").ToString();
 }
 }
 public string LastName
 {
 get
 {
 return (_userProfile[PropertyConstants.LastName].Value ?? "N/A").ToString();
 }
 }
 public string Username
 {
 get
 {
 return (_userProfile[PropertyConstants.UserName].Value ?? "N/A").ToString();
 }
 }
 public string WorkPhone
 {
 get
 {
 return (_userProfile[PropertyConstants.WorkPhone].Value ?? "N/A").ToString();
 }
 }
 public string Office
 {
 get
 {
 return (_userProfile[PropertyConstants.Office].Value ?? "N/A").ToString();
 }
 }
 public string Department
 {
 get
 {
 return (_userProfile[PropertyConstants.Department].Value ?? "N/A").ToString();
 }
 }
 public string Title
 {
 get
 {
 return (_userProfile[PropertyConstants.Title].Value ?? "N/A").ToString();
 }
 }
 public string Manager
 {
 get
 {
 return (_userProfile[PropertyConstants.Manager].Value ?? "N/A").ToString();
 }
 }
 public string AboutMe
 {
 get
 {
 return (_userProfile[PropertyConstants.AboutMe].Value ?? "N/A").ToString();
 }
 }
 public string PersonalSite
 {
 get
 {
 return (_userProfile[PropertyConstants.PersonalSpace].Value ?? "N/A").ToString();
 }
 }
 public string Picture
 {
 get
 {
 return (_userProfile[PropertyConstants.PictureUrl].Value ?? "N/A").ToString();
 }
 }
 public string Website
 {
 get
 {
 return (_userProfile[PropertyConstants.WebSite].Value ?? "N/A").ToString();
 }
 }
 public string PublicSiteRedirect
 {
 get
 {
 return (_userProfile[PropertyConstants.PublicSiteRedirect].Value ?? "N/A").ToString();
 }
 }
 public string DottedLineManager
 {
 get
 {
 return (_userProfile[PropertyConstants.Dottedline].Value ?? "N/A").ToString();
 }
 }
 public string Responsibilities
 {
 get
 {
 return (_userProfile[PropertyConstants.Responsibility].Value ?? "N/A").ToString();
 }
 }
 public string Skills
 {
 get
 {
 return (_userProfile[PropertyConstants.Skills].Value ?? "N/A").ToString();
 }
 }
 public string PastProjects
 {
 get
 {
 return (_userProfile[PropertyConstants.PastProjects].Value ?? "N/A").ToString();
 }
 }
 public string Interests
 {
 get
 {
 return (_userProfile[PropertyConstants.Interests].Value ?? "N/A").ToString();
 }
 }
 public string Schools
 {
 get
 {
 return (_userProfile[PropertyConstants.School].Value ?? "N/A").ToString();
 }
 }
 public string SIPAddress
 {
 get
 {
 return (_userProfile[PropertyConstants.SipAddress].Value ?? "N/A").ToString();
 }
 }
 public string Birthday
 {
 get
 {
 return (_userProfile[PropertyConstants.Birthday].Value ?? "N/A").ToString();
 }
 }
 public string MySiteUpgrade
 {
 get
 {
 return (_userProfile[PropertyConstants.MySiteUpgrade].Value ?? "N/A").ToString();
 }
 }
 public string DontSuggestList
 {
 get
 {
 return (_userProfile[PropertyConstants.DontSuggestList].Value ?? "N/A").ToString();
 }
 }
 public string HireDate
 {
 get
 {
 return (_userProfile[PropertyConstants.HireDate].Value ?? "N/A").ToString();
 }
 }
 public string LastColleagueAdd
 {
 get
 {
 return (_userProfile[PropertyConstants.LastColleagueAdded].Value ?? "N/A").ToString();
 }
 }
 public string OutlookWebAccessURL
 {
 get
 {
 return (_userProfile[PropertyConstants.OutlookWebAccessUrl].Value ?? "N/A").ToString();
 }
 }
 public string Assistant
 {
 get
 {
 return (_userProfile[PropertyConstants.Assistant].Value ?? "N/A").ToString();
 }
 }
 public string WorkEmail
 {
 get
 {
 return (_userProfile[PropertyConstants.WorkEmail].Value ?? "N/A").ToString();
 }
 }
 public string MobilePhone
 {
 get
 {
 return (_userProfile[PropertyConstants.CellPhone].Value ?? "N/A").ToString();
 }
 }
 public string Fax
 {
 get
 {
 return (_userProfile[PropertyConstants.Fax].Value ?? "N/A").ToString();
 }
 }
 public string HomePhone
 {
 get
 {
 return (_userProfile[PropertyConstants.HomePhone].Value ?? "N/A").ToString();
 }
 }
 public Guid ID
 {
 get
 {
 return _userProfile.ID;
 }
 }

 }
Categories: MOSS, SharePoint 2007, c# Tags:

“Column is constrained to be unique. Value is already present.” Error with in-memory table row inserts

June 25th, 2017 Michael Bell No comments

With my in-memory log-hit table I talked about in my last entry, I started getting these errors a few times a day, and it was enough to bomb the whole app:
Column ‘blahblah’ is constrained to be unique.  Value ‘-4862′ is already present.
Column ‘blahblah’ is constrained to be unique.  Value ‘-4847′ is already present.
Column ‘blahblah’ is constrained to be unique.  Value ‘-4768′ is already present.

Let me show you how the ‘blahblah’ column is built in the table construction:
DataColumn dc;

dc = new DataColumn(“HitID”, typeof(Int32));
dc.Unique = true;
dc.AutoIncrement = true;
dc.AutoIncrementSeed = -1;
dc.AutoIncrementStep = -1;
_MyTable.Columns.Add(dc);

So how in the world is this happening? Let me show the piece of code that was throwing the exception:
DataRow row = MemoryTables.HitList.NewRow();
row["FileID"] = Convert.ToInt32(context.Request.QueryString["fi"]);
row["FileName"] = fi.Name;
row["Username"] = _Username;
row["MemberID"] = _MemberID;
row["Success"] = true;
row["Bytes"] = fi.Length;
MemoryTables.HitList.Rows.Add(row);

Fairly straight forward.. right? With each hit to an image, this thing fires and inserts a new row into the in-memory table. About 20 rows get inserted a second. After much trial and error, I completely eliminated this problem by re-arranging a few lines of code. The new code reads:
DataRow row = MemoryTables.HitList.NewRow();
MemoryTables.HitList.Rows.Add(row);
row["FileID"] = Convert.ToInt32(context.Request.QueryString["fi"]);
row["FileName"] = fi.Name;
row["Username"] = _Username;
row["MemberID"] = _MemberID;
row["Success"] = true;
row["Bytes"] = fi.Length;

By creating a new row and adding it to the table before I populate it with any values, I eliminate my problem. I’d love to hear an explanation if anyone has one…

Categories: ASP.NET, c# Tags:

Rendering the HTML Output of a Server Control

June 25th, 2017 Michael Bell No comments

I recently found a neat trick to render the output of a control without actually having to add the control itself to a page or control. I found this very handy when trying to use a site template that everything must fit in, and the controls may have various locations within the page that they need rendered. In my case, I had HTML graphics comps that had specific spots in it that I would need to place specific controls. The graphics comps could be swapped out on the fly, and the controls would need to be rendered in different places based on which graphics comp was used. See what I did here to render the control HTML within the “CONTENTHERE” placeholder of the graphics design comp HTML.

ThemeObject to = bl.getTheme(siteID);

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter tw = new HtmlTextWriter(sw);

GalleryControl gallery = new GalleryControl();
gallery.ID = “gallery”;    
gallery.RenderControl(tw);
sHTML = sb.ToString();
sHTML = to.Body.Replace(“CONTENTHERE”, sHTML);

Categories: ASP.NET, c# Tags:

.NET Time Picker Control

June 25th, 2017 Michael Bell 6 comments

I got this into a “release” state today.. and thought I’d put it out there for anyone who wants to use it. It’s a Windows looking time picker control. Have a look!

http://www.MichaelKBell.com/TimePicker

Categories: ASP.NET, Whatever, c# Tags: