Saturday, August 14, 2010

Set Account As SharePoint System Account

In my previous two post related to SharePoint System Account i explain how to display you custom “DOMAIN/<<UserName>>” instead of “System Account”. But in this post i am going to explain different thing opposite to previous post.

Previous Posts : Post1 Post2

There are two way to achieve this thing.

1. Go To Central Admin Site
2. Security –> Configure Service Accounts
3. Select your application pool
4. then Select an account for this component (Select your account)

If your account is not already register as manage account then click on “Register new managed account”.
Another way to do same thing is

1. Go To Central Administration.
2. Click Application Management
3. Click Manage Web Application
4. Choose your web application
5. Click on “User Policy”
6. When “Policy for Web Application” popup open click on “Add User”

7. Click next

8. In this add users for which you want to display that account as “System Account”. Make sure you have “Account operates as system” checkbox selected.

Let me know your comment and view on this.

SharePoint/System Account Settings

In my previous post about SharePoint system account, i explain that how to configure account so that you can see your DOMAIN/<<UserName>> account as System Account.

But to do so you need SharePoint Central Administrator site permission. There is another way to do same thing using coding. ( Little bit trick :))

There is hidden List called “User Information List” in SharePoint site.You can find system account and update that listitem for “System Account”.

1. (Before Update Item)
2. Custom code to update item.


3.  In above code you can replace “your name” with your desired name.
4. After you can see in profile and Upper Right corner of your site.

You can customize any account using above code. Sometime you want friendly name instead DOMAIN\<<UserName>>

Let me know your comment on this.

SharePoint System Account Issue

SharePoint\System account is special account. Sometime it happens that when you login using DOMAIN/<<UserName>> is display as “System Account”. (Following image)


This is because of when application created or extended, during that time which account specify for application pool identity that consider as “SharePoint/System” account.

But if you want to display your username instead of “System Account” following are the solutions for that.

1. Go to Central Administration Site
2. Go to Security –> Configure Service Account
3. Next page you can see that “Credential Management”.
4. Select your application pool.
5. Select different account. (Other than your account). Which ever account you specify over here for that you can see “SharePoint/System” account.
6. If you still want that your application pool identity should be your name then manually set using IIS Manager.

Let me know if you still have any question about it.

Sunday, July 18, 2010 MVC Routing - Part1

In MVC Routing works following way and need to register in Application_Start of Global.asax

Default Route when MVC Application created

   "Default", // Route name
   "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Default", action = "Index", id = UrlParameter.Optional });

Default route has placeholder that done most of work.

For example :

if request is made for http://<<yoursite>//Home/Index.
This will call HomeController’s Index method.

if request is made for http://<<yousite>//Home/Index/1
This will call HomeController’s Index method with argument value “1”.

Sample Controller:
public class HomeController : Controller
        public ActionResult Index(string id)
            return new ContentResult() { Content = "This is Index" };

Next Part will going to give you detail about “Slugish Url”. 4.0 Url Routing

In 4.0 , New functionality included for URL Routing.

For Example : ( Application_Start)

When Browser request for http://<<your site>>/Home, It will route to page Default.aspx

And Page has some property that allow you to get route data, Page.RouteData

Even generic route is also possible.


Now When request made for Url : http://<<yoursite>/Test It automatically route to Test.aspx

One more thing true about 4.0 routing is even though routing is done, there is still possible that direct request for “ASPX” pages.

To disable that

1. from UI (IIS 7.0 or later)
       - Go to inetmgr
       - In Feature View go to “Request Filtering”
       - Click Deny FileName Extension 

2.  Using main web.config file of your application          
     <modules runAllManagedModulesForAllRequests="true" />
                    <add fileExtension=".aspx" allowed="false" />
    - Add Module tag with runAllManagedModulesForAllRequests = “true”
    - Add requestfiltering with fileextension=”.aspx” and “allowed=false”.

Let me know your comment on this.

Sunday, June 20, 2010

Process Bitmap Faster In .NET

In .NET (C# or you can process Bitmap pixel by pixel.

Here is the example of simple code. ( Use Example of Gray Scale)

System.Drawing.Image img = System.Drawing.Bitmap.FromFile(@"C:\Test.jpg");
Bitmap bmp = (Bitmap)img;
         for (int x = 0; x < bmp.Width; x++)
             for (int y = 0; y < bmp.Height; y++)
                Color c =  bmp.GetPixel(x, y);
                int gray = (int)((c.R + c.G + c.B)/3);

Above code works fine but it takes to much time to process.In order to process Bitmap Image Faster “BitmapData” is powerful class in .NET. Here is the example of that class.

System.Drawing.Image img = System.Drawing.Bitmap.FromFile(@"C:\Test.jpg");
Bitmap bmp = (Bitmap)img;           
System.Drawing.Imaging.BitmapData data = bmp.LockBits(new Rectangle() { X = 0, Y = 0, Width = bmp.Width, Height = bmp.Height }, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
IntPtr ptr = data.Scan0;           
int bytes  =data.Stride * bmp.Height;
byte[] rgbValues = new byte[bytes];           
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
int val = 0;
for (int counter = 0; counter < rgbValues.Length; counter += 3)
    val = rgbValues[counter + 0] + rgbValues[counter + 1] + rgbValues[counter + 2];
    rgbValues[counter+0] =  (byte)(val/3);
    rgbValues[counter+1] =  (byte)(val/3);
    rgbValues[counter+2] =  (byte)(val/3);
System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);

This code works must faster than previous code. Test it with PictureBox Control and See the effect… :)

Translate content using Bing Service In MVC

I used Translate Bing Service API in SharePoint Translate Web Part. Same API can be used with MVC. Here i am writing small extension method for HtmlHelper.

public static class HtmlHelperExtention
        public static string Tranlate(this System.Web.Mvc.HtmlHelper objHelper,string inputContent,string sourceLanguage,string targetLanguage)
            string apikey = System.Configuration.ConfigurationManager.AppSettings["BingAPI"];
            Soap s = new Soap();
            string frenchoutputtext = s.Translate(apikey, inputContent, sourceLanguage, targetLanguage);
            return frenchoutputtext;           

In View Of MVC you should write this.

    <%=  Html.Tranlate("<div>This is Translation test.</div>","en","fr") %>

1. Valid API key required.
2. Need to Add Proxy Class to user “Bing Translate Service”.

Hope this will help……. 

Sunday, January 31, 2010

Custom GroupBox Control for Silverlight 3

In previous post i put xaml that allow to create GroupBox using XAML.

Here i am adding custom groupbox control.


Download link :   GroupBox control for Silverlight 3

Codeplex Link :  Silverlight3 GroupBox

GroupBox control for Silverlight3

GroupBox control is not available in Silverlight 3, but you can create GroupBox control using following XAML.

<Border CornerRadius="10" Background="AliceBlue" BorderBrush="Black" BorderThickness="1" Margin="10,10,10,10" Width="400" x:Name="Test">
                <Border Margin="20,-10,0,0" Background="AliceBlue" HorizontalAlignment="Left">
                    <TextBlock Text="User Setting" Margin="10,0,10,0" FontWeight="Bold"></TextBlock>
              <!-- Put your content -->
In above XAML you can replace <!-- Put your content –> with your data inside groupbox .

For Example :


Let me know your comment on this.

Saturday, January 16, 2010

Silverlight 3: Programmatically Validate Textbox

In previous post about validation in Silverlight, I explained the How binding is used to validate data ? .

Here i am going to explain how to validate Textbox ( Any control that has validation states group).

There are three validation states. 1. Valid 2. InvalidFocused 3. InvalidUnfocused. Now use VisualStateManager to change the state of control. Here is common method.

public void SetState(Control c, string message,string state)     
if (state == "Invalid")
if (c.Focus())
VisualStateManager.GoToState(c, "InvalidFocused", false);
VisualStateManager.GoToState(c, "InvalidUnfocused", false); ToolTip tp = ((Grid)VisualTreeHelper.GetChild(c, 0)).FindName("validationTooltip") as ToolTip;
tp.DataContext = message;
tp.Template = LayoutRoot.Resources["ValidationToolTipTemplate"] as ControlTemplate;
VisualStateManager.GoToState(c, "Valid", false);

In XAML Page you have to specify control template.

<ControlTemplate x:Key="ValidationToolTipTemplate">
<Grid x:Name="Root" >
<Border Margin="4,4,-4,-4" Background="#152A2E31" CornerRadius="4"/>
<Border Margin="3,3,-3,-3" Background="#252A2E31" CornerRadius="4"/>
<Border Margin="2,2,-2,-2" Background="#352A2E31" CornerRadius="4"/>
<Border Margin="1,1,-1,-1" Background="#452A2E31" CornerRadius="4"/>
<Border Background="#FFDC000C" CornerRadius="4"/>
<Border CornerRadius="4">
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#66FFFFFF"/>
<GradientStop Color="#66000000" Offset="1"/>
<GradientStop Color="#00E5E5E5" Offset="0.1"/>
<GradientStop Color="#00161616" Offset="0.9"/>
<TextBlock Margin="8,3,8,4" MaxWidth="250" UseLayoutRounding="false" Foreground="White" Text="{Binding}" TextWrapping="Wrap"/>

This control template is used for validation tooltip.

Control like Textbox,listbox ,combobox,checkbox has validation states so you can use this method.


if(txtFirstName.Text == “”)
SetState(txtFirstName , “Invalid”, “Please enter first name”);

Let me know you comment on this.