Archive | Technical RSS feed for this section

article related to computer technology such as C#, DotNetNuke, ASP.NET etc

C# – EpochTime

Snipplet code to convert current date time to epoch time
you may go to http://www.epochconverter.com/ to check the result.

public long GetEpochTime()
        {
            DateTime dtCurTime = DateTime.Now;
            DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 00:00:00 AM");
            TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);

            long epochtime;
            epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
            return epochtime;
        }

Incoming search terms:

  • diary in c#
  • c# converttodatetime epoch
  • Convert ToDateTime() long
  • EpochTime C#
  • getepochtime c#
  • learn c#

SharePoint 2010 – return XmlDocument with WCF Rest WebService

Objective: to return XmlDocument from WCF REST WebService via URL.

Creating a WCF WebService is straight forward, but to create a WCF WebService to host under SharePoint 2010 you need extra steps to accomplish.
This is my first time to develop WCF RestFul WebService. Many of you may familiar with REST if you are the SharePoint Developer.

I will attach a zip file of a working solution at the end of this post.

To Create WCF Service

  • New Project -> WCF -> WCF Service Library
  • it will create 2 class files for you. (we need these 2 files)

To Create SharePoint WCF Service

  • New Project -> SharePoint -> Empty SharePoint Project
  • Map ISAPI SharePoint Folder
  • Create a text file and rename it to “BuckOfficesService.svc”
  • Create another text file and rename it to “web.config”
  • Copy 2 cs files from WCF Service Project (Rename them as BuckOfficeService.cs and IBuckOfficesService.cs)
  • Make sure those references added in the project as well
  • Microsoft.SharePoint
  • Microsoft.SharePoint.Client.Runtime
  • Microsoft.SharePoint.Security
  • System.ServiceModel
  • System.ServiceModel.Web


Click it for clear view

 

So I wanted to return a XmlDocument from Rest WCF WebService.
You need to make sure you add [XmlSerializerFormat] in your Interface class (it will return error when you try to run the service) before or after [ServiceContract]

Deploy the solution to your SharePoint Server.
Launch IE with http://localhost/_vti_bin/buckofficesservice.svc/getbuckoffices


You may download the full working source code for HTTP only [here]

To cater for HTTPS, you need to add extra line in web.config (those red highlighted)
Click the image for better view

Incoming search terms:

  • sharepoint 2010 custom web service rest return xml
  • wcf rest xmldocument
  • sharepoint 2010 webservice return xml
  • sharepoint web service endpoint documents
  • sharepoint with wcf rest
  • unable to return xmldocument from wcf
  • asp net xml webservice return int
  • wcf return xmldocument
  • wcf service return xmldocument
  • wcf to send xml document

SharePoint 2010 – Create Custom Central Admin Menu

Usually the development team create some application pages to park under _layouts directory.

When an application page involved User Profile Services or Deletion, the application just can’t work properly without Service Account.

Fortunately, One of the solution is deploy those applications under Central Admin Page.

That’s 2 custom applications under ’Bucknet 2.0 Support Application’.

This is what I have in Visual Studio 2010, click the image for bigger size so that you able to see xml script in Elements.xml

First you need to create ‘Element’ with above xml script.

Map the admin folder, and create new folder for each applications.

Also, do not forget to set the ‘scope’ to ‘Site’ or ‘Farm’ in Webpart’s feature then deploy to SharePoint server.

if you want to know how to deploy an application page to Central Administration with steps. Click http://msdn.microsoft.com/en-us/library/ff798467.aspx for more information.

Incoming search terms:

  • sp 2010 custom central administration
  • sharepoint 2010 create central admin page
  • customize sharepoint 2010 central admin
  • sharepoint 2010 diary
  • custom menu sharepoint 2010
  • sharepoint central admin add new menu scope
  • sharePoint 2010 createing new central admin
  • sharepoint 2010 custom admin page
  • sharepoint 2010 custom central admin page
  • sharepoint 2010 custom central administration page

Check File Exist from Remote Server

Some snippet code for checking file exists from remote server using WebClient.

        private bool RemoteFileExists(string url)
        {
            bool bResult = false;
            using (WebClient client = new WebClient())
            {
                try
                {
                    client.UseDefaultCredentials = true;
                    Stream stream = client.OpenRead(url);
                    if (stream != null)
                        bResult = true;
                    else
                        bResult = false;
                }
                catch
                {
                    bResult = false;
                }
            }
            return bResult;
        }

Incoming search terms:

  • asp net client file exists
  • Remote Email Exist
  • php check if file exists on remote server
  • php check if file exist remote server
  • php check file exists remote server
  • net webclient file exists
  • httpfile exist check
  • how to check whether the URL exist in the remote server using WebClient in asp net
  • check if file exists on remote server with no share c#
  • check file exists remote server php

SharePoint 2010 – GetAllTerms by Group

Recently received an assignment to retrieve all the terms belong to a specific group.
Here a snippet code to achieve the objective.

For Instance, I want to retrieve all terms under “SMR”


                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite site = SPContext.Current.Web.Site;
                    TaxonomySession session = new TaxonomySession(site);

                    Group termGroup = session.TermStores[0].Groups["SMR"];
                    List<string> colSMRTerm = new List</string><string>();
                    if (termGroup != null)
                    {
                        foreach (TermSet ts in termGroup.TermSets)
                        {
                            foreach (Term t in ts.GetAllTerms())
                            {
                                colSMRTerm.Add(t.Name.ToLower());
                            }
                        }
                    }
                }); 

Incoming search terms:

  • sharepoint get all terms from group
  • sharepoint 2010 get all terms
  • retrieving taxonomies sharepoint 2010 get all terms
  • c# sharepoint get all terms termset
  • sharepoint get terms site c#
  • sharepoint group by terms
  • sharepoint termcollection order terms c#
  • sharepoint terminology c#
  • taxonomy custom order getallterms sharepoint c#
  • Taxonomy Session runwithelevatedprivileges

SQL – Order by Ascending Order but NULL at the End

SQL script is common language for web/database developers.
Sometime, a little bit tricky when you want to accomplish a request sound simple but yet challenging.

Case Study:
To sort a list of records with ‘Last Name’ ascending, but to make sure NULL value of ‘Last Name’ must at the end.

SELECT	ID
		, LastName
		, FirstName
		, Email
		, Phone
		, Office
FROM
	Table
ORDER BY CASE  WHEN LastName = ''  THEN 1 ELSE 0 END, LastName

Incoming search terms:

  • account inurl:/guestbook asp?sent=
  • process inurl:/guestbook asp?sent=
  • free mp3 ascending order
  • case inurl:/comments asp
  • sql order null at the end
  • sql sorting null at the end

SharePoint 2010 Programmatically Get Activities That I Following

Received an assignment to create a view page for mysite profile, one of the challenge is to get the checkboxlist value from database.

Found this (http://madalina.blog.com/2011/02/09/sharepoint-2010-programmatically-change-activities-that-i-follow/) from google search result.

Article above saved my time to get a list of data from “Activity That I m Following” but to get the checkboxlist value of “Activity That I m Following” seem not very straight forward.

2 API you need to pay attention in order to get those checkboxlist value, which are ActivityManager and ActivityPreferencePerType

Here some snippet code to retrieve the checkboxlist value, as for updating the value, you may refer the above URL for more information.

                        SPServiceContext context = SPServiceContext.GetContext(SPContext.Current.Site);
                        UserProfileManager uprofileManager = new UserProfileManager(context);

                        if (uprofileManager.UserExists(GetDecodedAccountName(hAcctName.Value)))
                        {
                            UserProfile up = uprofileManager.GetUserProfile(GetDecodedAccountName(hAcctName.Value));

                            ActivityManager activityManager = new ActivityManager(up, context);

                            List<activitypreferencepertype> activityPrefsPerTypes = activityManager.ActivityPreferences.GetActivityPreferencesPerType();

                            foreach (ActivityPreferencePerType ab in activityPrefsPerTypes)
                            {
                                foreach (ActivityType a in activityManager.ActivityTypes)
                                {
                                    if (ab.ActivityType.Equals(a))
                                    {
                                        if (!a.ActivityTypeName.ToLower().Contains("internal_"))
                                        {
                                            string source = String.Concat("$Resources:", a.ActivityTypeNameLocStringName);

                                            string resourceFile = a.ActivityTypeNameLocStringResourceFile;

                                            string displayName = SPUtility.GetLocalizedString(source, resourceFile, SPContext.Current.Web.Language);
                                            lblActivity.Text += string.Format("<input type=\"checkbox\" {0} disabled=\"disabled\" />" + displayName + "<br />", ab.IsSet ? Constants.YES : Constants.NO);
                                        }
                                    }
                                }
                            }
                        }

Enjoy.

Incoming search terms:

  • activities i am following sharepoint 2010
  • powershell activitymanager
  • sharepoint 2010 activitymanager
  • ActivityManager PowerShell
  • sharepoint activities i am following
  • sharepoint activitymanager
  • sharepoint 2010 activity manager
  • sharepoint 2010 activity events values
  • powershell sharepoint 2010 activityManager
  • sharepoint 2010 programmatically get current user

SharePoint2010 – MySite’s Email Notification

Location: MySite – Edit Profile – Newsfeed Settings – Email Notification

To know what is the value return for the combination of the check boxes it will return an integer with semicolon, “0;” for instance.

0 – All Checked
1 – Second and Third check box
2 – First and Third check box
3 – Third check box
4 – First and Second check box
5 – Second check box
6 – First check box
7 – no checked

Hope it helps.

Incoming search terms:

  • mysite notification email
  • mysite email alerts
  • my site e-mail notifications sharepoint 2010
  • custom email notification sharepoint 2010 using c
  • sharepoint 2010 My Site E-mail Notifications
  • sharepoint 2010 my site notification
  • sharepoint 2010 news feed settings email notifications
  • sharepoint 2010 newsfeed settings email notifications
  • sharepoint 2010 notification c#
  • sharepoint 2010 notification mail c

SharePoint2010 – Get TimeZone Value from UserProfileManager

I want to grab the timezone value from User Profile but seem like i got the an object return from API instead, Snippet code below will help you to get the actual value.

SPServiceContext context = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager uprofileManager = new UserProfileManager(context);

if (uprofileManager.UserExists(sUserName))
{
UserProfile up = uprofileManager.GetUserProfile(sUserName);

SPTimeZone spTimeZone = up[PropertyConstants.TimeZone].Value as SPTimeZone;

lblTimeZone.Text = spTimeZone.Description;
}

Incoming search terms:

  • sharepoint userprofilemanager
  • c# sharepoint timezone
  • propertyconstants timezone value
  • timezone from user profile to sptimezone
  • sharepoint 2010 sptimezone profile
  • sptimezone
  • sharepoint 2010 get sptimezone by id
  • sharepoint server timezone C#
  • sharepoint timezon taipei
  • sharepoint timezone user profile get value

SharePoint2010 – SPClaimProviderManager i:0#.w|

Recently received a task to develop a custom side menu webpart for SharePoint 2010 – MySite.
The webpart working well in my local machine but not Development Server because it is using Claims Based Authentication. You may see some syntax like “i:0#.w|” infront of your account name (http://localhost/my/person.aspx?accountname=i:0#.w|local/admin)

To solve this problem, you need to decode the account name.


using Microsoft.SharePoint.Administration.Claims;

SPClaimProviderManager mgr = SPClaimProviderManager.Local;
string strDecodedLoginName = "";
if (mgr != null)
{
      try
      {
             strDecodedLoginName = mgr.DecodeClaim(strLoginName).Value;

       }
       catch (Exception ex)
       {
         System.Diagnostics.Debug.WriteLine(" Failure decoding claim for user: " + strLoginName);
         System.Diagnostics.Debug.WriteLine(ex.ToString());
         }
}
else
{
       strDecodedLoginName = SPContext.GetContext(HttpContext.Current).Web.CurrentUser.LoginName;
}
Related Posts with Thumbnails

Incoming search terms:

  • SPClaimProviderManager
  • i:0# w|
  • i:0# w
  • decodeclaim
  • SPClaimProviderManager Local
  • SPClaimProviderManager Local DecodeClaim
  • SPClaimProviderManager DecodeClaim
  • sharepoint 2010 i:0# w
  • sharepoint 2010 i:0# w|
  • sharepoint 2010 0# w|
Get Adobe Flash playerPlugin by wpburn.com wordpress themes