Update profiles property in SharePoint 2007 programmatically without BDC

Thursday, 30 July 2009 17:04 by myro

SharePoint 2007 (MOSS) allows you import profiles as a primary source in 2 different ways: using Active Directory o LDAP imports. Remeber that this are the only ways to perform this task. But when comes to update a profile's properties you can choose if you want to use Shared Services defining new import connections or using the SharePoint's object model. This post will cover only the programmatical way to update profile's properties: this is a much faster way than writing a new Buisness Data Catalog (BDC) application. A valid alternative to Buisness Data Catalog (BDC) is to create a simple Console Application and add it into your server's farm scheduled tasks,or, if you prefer, you could create a SharePoint's Timed Job which will be executed whenerver you want. Next, I will cover how to retrive user's UserProfile object and how to update it.
Here's the code snipped:

using (SPSite site = new SPSite("http://YOUR_SITE_URL")
{
       ServerContext context = ServerContext.GetContext(site);
       UserProfileManager userManager = new UserProfileManager(context);
       UserProfile userProfile = userManager.GetUserProfile("DOMAIN\\USERID");
       if (userProfile != null)
       {
            userProfile["Property1"].Value = "Your propery value";
            userProfile["Property2"].Value = "Your propery value";
                userProfile.Commit();
     }
}

Simple right?

Most organizations, stores user's properties in Active Directory but they can also store some of this properties into SQL tables.  You can merge all those properties in SharePoint's profiles and have them all without messing around with BDCs. The next method will return a DataTable and with the collaboration of the first snippet, you can easly build your own SharePoint's profile updater:

private static DataTable ReadTable(string dataTableName, string connectionString, string query)
{

    DataTable dataTable = new DataTable(dataTableName);
    try
    {
        SqlDataAdapter dataAdapter = new SqlDataAdapter(query,
            connectionString);
        dataAdapter.Fill(dataTable);
        dataAdapter.Dispose();
    }
    catch (Exception e)
    {
        Console.WriteLine(e.ToString());
    }
    return dataTable;
}

Read this article to understand how can you build you SharePoint's timed job and merge it with this two simple snippets.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (5) | Comment RSSRSS comment feed

Get your linux computer system summary

Tuesday, 28 July 2009 20:01 by myro

In this post, I'm going to show you som common shell command in linux that can helps you in obtaining your computer summary. This commands are useful if you expect a problem with your linux distribution, but you don't know where you should start in solving your problem.

Print system information

uname -a
Linux debian 2.6.30-bpo.1-686 #1 SMP Sun Jun 28 18:13:49 UTC 2009 i686 GNU/Linux

List all PCI devices

lspci -v -nn
00:00.0 Host bridge [0600]: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub [8086:2a40] (rev 07)
    Subsystem: Sony Corporation Device [104d:9035]
    Flags: bus master, fast devsel, latency 0
    Capabilities: [e0] Vendor Specific Information <?>
    Kernel modules: intel-agp

00:01.0 PCI bridge [0604]: Intel Corporation Mobile 4 Series Chipset PCI Express Graphics Port [8086:2a41] (rev 07) (prog-if 00 [Normal decode])
    Flags: bus master, fast devsel, latency 0
    Bus: primary=00, secondary=01, subordinate=01, sec-latency=0
    I/O behind bridge: 00006000-00006fff

.......

List the status of modules in the Linux Kernel

lsmod
Module                  Size  Used by
binfmt_misc             7080  1
rfcomm                 30184  0
l2cap                  18112  5 rfcomm
bluetooth              46860  4 rfcomm,l2cap
vboxnetadp             66816  0
vboxnetflt             72288  0
.....

Cpu informations

cat /proc/cpuinfo
processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Core(TM)2 Duo CPU     P8400  @ 2.26GHz
stepping    : 6
cpu MHz        : 800.000

.....

Cpu frequency kernel information

cpufreq-info
cpufrequtils 004: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to cpufreq@lists.linux.org.uk, please.
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which need to switch frequency at the same time: 0
  hardware limits: 800 MHz - 2.27 GHz
  available frequency steps: 2.27 GHz, 2.27 GHz, 1.60 GHz, 800 MHz
  available cpufreq governors: powersave, userspace, conservative, ondemand, performance
  current policy: frequency should be within 800 MHz and 2.27 GHz.

......

List of currently registered port regions used for input or output communication with a device

cat /proc/ioports
0000-001f : dma1
0020-0021 : pic1
0040-0043 : timer0
0050-0053 : timer1
0060-0060 : keyboard
0064-0064 : keyboard
....

List number of interrupts per IRQ

 cat /proc/interrupts
            CPU0       CPU1      
   0:     311925     315345   IO-APIC-edge      timer
   1:       1584       1525   IO-APIC-edge      i8042
   8:         39         44   IO-APIC-edge      rtc0
   9:       2288       2253   IO-APIC-fasteoi   acpi
  12:         65         66   IO-APIC-edge      i8042
  16:         32         24   IO-APIC-fasteoi   uhci_hcd:usb1, uhci_hcd:usb6, firewire_ohci
  17:         12         13   IO-APIC-fasteoi   mmc0, HDA Intel

....

List USB devices

cat /proc/bus/usb/devices

T:  Bus=08 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
B:  Alloc=  0/800 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=1d6b ProdID=0002 Rev= 2.06
S:  Manufacturer=Linux 2.6.30-bpo.1-686 ehci_hcd
S:  Product=EHCI Host Controller
S:  SerialNumber=0000:00:1d.7
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   4 Ivl=256ms

....

List USB bus devices:

lsusb

Bus 008 Device 004: ID 054c:0377 Sony Corp.
Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 002: ID 05ca:183d Ricoh Co., Ltd
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 007: ID 04b8:010b Seiko Epson Corp. Perfection 1240
Bus 003 Device 006: ID 046d:c01d Logitech, Inc. MX510 Optical Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

I will try to keep this post updated as soon as i learn something new.. in the meanwhile, i want to say thx to http://www.klabs.be/ for prividing me this informations.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Linux
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

How to use explicit impersonation in SharePoint 2007

Tuesday, 28 July 2009 15:38 by myro

There are different ways for using impersonation in SharePoint 2007. Probably the most common way is calling the RunWithElevatedPrivileges method defined into the SPSecurity class. If you don't know how to impersonate using this method, you should visit the msdn reference.

But sometimes this approach doesn't work, infact this method is useless if you are trying to impersonate when writing event handlers. An another possible solution, is using the Explicit Impersonation in SharePoint 2007. This method will impersonate through user's SPUserToken class.

Here's the code snippet for impersonating a different user:

SPUser user = SPContext.Current.Web.AllUsers[@"DOMAIN\LOGINNAME"];
SPUserToken token = user.UserToken;
using (SPSite site = new SPSite(SPContext.Current.Site.Url,token))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists["YourList"];
        list.Items[0]["Title"] = "Your new title";
        list.Items[0].Update();
    }
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   , ,
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed

SharePoint 2007 hidden fields in SPList and SPDocumentLibrary

Monday, 27 July 2009 16:42 by myro

Developing against the SharePoint's 2007 lists (SPList) or document libraries (SPDocumentLibrary), allow you see item's proprieties hidden into fields that are unaccessible from the user interface (your browser). This post will simply list all the fields that are accessible from code (hidden or not). and can be a useful reference when you need to obtain some more information from your items. If you want to easly see all the fields that are hidden by yourself, you need to lunch this simple console application in debug mode and set a breakpoint just after the SPListItem istance:

private static void ReadSpListItemsProperties(string listUrl)
{
    using (SPSite site = new SPSite(listUrl))
    {
        using (SPWeb web = site.OpenWeb())
        {
            SPList list = web.GetListFromUrl(listUrl);
            if (list.Items.Count == 0)
            {
                return;
            }
            SPListItem item = list.Items[0];

        } // set your breakpoint here!
    }
}

Now using the quickwatch tool in Visual Studio you can see all the hidden fields:

A basic document library has at least 66 fields in MOSS and a SharePoint's list has 48. It's more than you have expected right? 
Ok, here's the list:

All Fieds into Moss Document Library:

  • ["ContentType"]
  • ["xd_Signature"]
  • ["_UIVersion"]
  • ["RepairDocument"]
  • ["GUID"]
  • ["ScopeId"]
  • ["SelectFilename"]
  • ["Modified"]
  • ["PermMask"]
  • ["InstanceID"]
  • ["_EditMenuTableEnd"]
  • ["LinkCheckedOutTitle"]
  • ["CheckedOutUserId"]
  • ["Created_x0020_By"]
  • ["FSObjType"]
  • ["owshiddenversion"]
  • ["WorkflowVersion"]
  • ["CheckoutUser"]
  • ["_UIVersionString"]
  • ["ProgId"]
  • ["HTML_x0020_File_x0020_Type"]
  • ["Title"]
  • ["IsCheckedoutToLocal"]
  • ["ParentLeafName"]
  • ["File_x0020_Type"]
  • ["ID"]
  • ["TemplateUrl"]
  • ["ParentVersionString"]
  • ["File_x0020_Size"]
  • ["FileSizeDisplay"]
  • ["_SharedFileIndex"]
  • ["VirusStatus"]
  • ["_ModerationComments"]
  • ["_IsCurrentVersion"]
  • ["FileDirRef"]
  • ["Combine"]
  • ["_ModerationStatus"]  
  • ["ServerUrl"]
  • ["_EditMenuTableStart"]
  • ["LinkFilenameNoMenu"]
  • ["_Level"]
  • ["Created_x0020_Date"]
  • ["LinkFilename"]
  • ["FileLeafRef"]
  • ["_CheckinComment"]
  • ["Order"]
  • ["Last_x0020_Modified"]
  • ["MetaInfo"]
  • ["xd_ProgID"]
  • ["Editor"]
  • ["_HasCopyDestinations"]
  • ["UniqueId"]
  • ["EncodedAbsUrl"]
  • ["CheckedOutTitle"]
  • ["WorkflowInstanceID"]
  • ["DocIcon"]
  • ["FileRef"]
  • ["_SourceUrl"]
  • ["_CopySource"]
  • ["Created"]
  • ["SelectTitle"]
  • ["Modified_x0020_By"]
  • ["Edit"]
  • ["BaseName"]
  • ["ContentTypeId"]
  • ["Author"]
  • All Fieds into Moss List:

  • ["ContentType"]
  • ["ID"]
  • ["Attachments"]
  • ["_UIVersion"]
  • ["GUID"]
  • ["ScopeId"]
  • ["Modified"]
  • ["PermMask"]
  • ["InstanceID"]
  • ["owshiddenversion"]
  • ["ProgId"]
  • ["WorkflowVersion"]
  • ["FSObjType"]
  • ["LinkFilename"]
  • ["_Level"]
  • ["_UIVersionString"]
  • ["EncodedAbsUrl"]
  • ["HTML_x0020_File_x0020_Type"]
  • ["Title"]
  • ["LinkTitleNoMenu"]
  • ["File_x0020_Type"]
  • ["ServerUrl"]
  • ["_ModerationComments"]
  • ["_IsCurrentVersion"]
  •  
  • ["_ModerationStatus"]
  • ["FileDirRef"]
  • ["Last_x0020_Modified"]
  • ["_EditMenuTableStart"]
  • ["LinkFilenameNoMenu"]
  • ["Editor"]
  • ["Created_x0020_Date"]
  • ["Order"]
  • ["FileLeafRef"]
  • ["DocIcon"]
  • ["MetaInfo"]
  • ["_HasCopyDestinations"]
  • ["UniqueId"]
  • ["WorkflowInstanceID"]
  • ["FileRef"]
  • ["_CopySource"]
  • ["Created"]
  • ["LinkTitle"]
  • ["SelectTitle"]
  • ["Edit"]
  • ["BaseName"]
  • ["_EditMenuTableEnd"]
  • ["ContentTypeId"]
  • ["Author"]
  • Immagine that you need to overwrite an item's sensitive informations such as who modified it or create it.
    A simple implementation could be:

    item["Author"] = yourAuthor;
    item["Created"] = yourDate;
    item["Editor"] = yourEditor;
    item["Modified"] = yourDate2;
    item.UpdateOverwriteVersion();

    Now that you learned how to perform a dirty update in Moss, you can try to mess around a little more with your SharePoint 2007.

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5
    Tags:   ,
    Categories:   SharePoint 2007
    Actions:   Bookmark and Share | Permalink | Comments (3) | Comment RSSRSS comment feed

    DateTime.ToString() common format patterns in .NET

    Thursday, 23 July 2009 15:24 by myro

    When it comes to convert a DateTime into a specific culture format using the .NET Framework, you should use the ToString() method of your DateTime object, passing the correct pattern in string which defines your format. This table can helps you out in building your own format:

     DateTime Pattern Sample result
    MM/dd/yyyy 08/22/2006
    dddd, dd MMMM yyyy Tuesday, 22 August 2006
    dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2006 06:30
    dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2006 06:30 AM
    dddd, dd MMMM yyyy H:mm Tuesday, 22 August 2006 6:30
    dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2006 6:30 AM
    dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07
    MM/dd/yyyy HH:mm 08/22/2006 06:30
    MM/dd/yyyy hh:mm tt 08/22/2006 06:30 AM
    MM/dd/yyyy H:mm 08/22/2006 6:30
    MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
    MM/dd/yyyy HH:mm:ss 08/22/2006 06:30:07
    MMMM dd August 22
    MMMM dd August 22
    yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2006-08-22T06:30:07.7199222-04:00
    yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2006-08-22T06:30:07.7199222-04:00
    ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Tue, 22 Aug 2006 06:30:07 GMT
    ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Tue, 22 Aug 2006 06:30:07 GMT
    yyyy'-'MM'-'dd'T'HH':'mm':'ss 2006-08-22T06:30:07
    HH:mm 06:30
    hh:mm tt 06:30 AM
    H:mm 6:30
    h:mm tt 6:30 AM
    HH:mm:ss 06:30:07
    yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2006-08-22 06:30:07Z
    dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07
    yyyy MMMM 2006 August
    yyyy MMMM 2006 August


    If you are not practical in how to use this patterns, take a look to this samples:

    Console.WriteLine(DateTime.UtcNow.ToString());
    // writes in american date time format:  7/23/2009 1:38:32 PM

    Console.WriteLine(DateTime.UtcNow.ToString("dd/MM/yyyy"));
    //writes in europian date time format: 23/7/2009

    Console.WriteLine(DateTime.UtcNow.ToString("dddd, dd MMMM yyyy HH:mm:ss"));
    //writes in american long time format: Thursday, 23 July 2009 13:38:32

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5
    Tags:  
    Categories:   .NET
    Actions:   Bookmark and Share | Permalink | Comments (1) | Comment RSSRSS comment feed