Thursday, June 16, 2011

Programmatically retrive content database name for Sharepoint Web Application


using (SPSite startSite = new SPSite("url"))
{
SPFarm farm = startSite.WebApplication.Farm;
SPWebService service = farm.Services.GetValue("");

foreach (SPWebApplication webApplication in service.WebApplications)
{
foreach (SPSite site in webApplication.Sites)
{
Console.WriteLine(string.Format("{0} - {1}", site.Url, site.ContentDatabase.Name));
}
}
}

14 comments:

  1. Hi

    Can you tell me how to programatically get user profile DB from a webpart

    ReplyDelete
  2. can you please be more clear with your question..

    ReplyDelete
  3. If i am not wrong you need the database name from for user profile right?? if so ... then create a webpart project in visual studio and put a button on that and write the above code in code behind, put a text box or list also and instead of "Console.WriteLine(string.Format("{0} - {1}", site.Url, site.ContentDatabase.Name));" just put textbox.text=textbox.text+site.contentdatabase.name.tostring() or listbox.items.add(site.contentdatabase.name);
    hope this fulfill your requirement...

    ReplyDelete
  4. Hi

    My problem is that i am trying to update the profile of a user through a web part and for that i want to read the database name so that i can update the value using Client object model ..thank you the suggestion

    ReplyDelete
  5. i dont know nw whether you can update the database directly using client object model... better you use sharepoint apis to update the user profile

    mean while i research and check you go through this

    http://msdn.microsoft.com/en-us/library/ms518939.aspx

    you know to make visual web parts in visual studio right if not let me know...

    ReplyDelete
  6. No Javascript API is avaiable to update the user profiles. You can however, use UserProfileService.asmx web service to modify user profiles

    ReplyDelete
  7. check this
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace UserProfileWebServiceApp
    {
    class Program
    {
    public static localhost.UserProfileService myService =
    new localhost.UserProfileService();
    UserProfileWebService.localhost.PropertyData[] newdata =
    new UserProfileWebService.localhost.PropertyData[1];
    newdata[0] =
    new UserProfileWebService.localhost.PropertyData();
    newdata[0].Name = "HomePhone";
    newdata[0].Values = new ValueData[1];
    newdata[0].Values[0] = new ValueData();
    newdata[0].Values[0].Value = "nnnnnnnnnnn";
    newdata[0].IsValueChanged = true;
    myService.ModifyUserPropertyByAccountName("domainname\\username",
    newdata);

    }
    }

    http://msdn.microsoft.com/en-us/library/ms544240.aspx

    ReplyDelete
  8. http://msdn.microsoft.com/en-us/library/websvcuserprofileservice.aspx

    ReplyDelete
  9. Thank you very much the MSDN link is the one i am looking for ,,i will construct the visual web part ..Thanks a alot..

    ReplyDelete
  10. http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/802dbc0f-544e-4bfe-80a1-8bd5af5c8fea/

    ReplyDelete
  11. Hi
    I appreciate your efffort.It is nice idea to create a informative sie. It happened to see your website page as well as several written piece. Is exceedingly good type publishing.
    Ecommerce developer

    ReplyDelete
  12. Hi,

    Can i get the list of user profiles which matches 2 different property values, e.g. If user is "active" and user manager is "xyz". i dont want to loop here. i need at a time like quering the DB or list.

    Please help

    ReplyDelete
    Replies
    1. Better ask your question here
      @
      http://social.technet.microsoft.com/Forums/en-us/sharepoint2010general/threads
      also
      meanwhile i will also try to find out the way.

      Delete

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...