Moving to new blog.

Moving to the New Blogger Interface. We introduced a new user interface that makes it easier for view code, find article and sharing.

Kindly to access to http://www.sharedude.net for serve you better. Thanks for all your support.

Posted in Uncategorized | Leave a comment

Future of ASP.net and MVC?

Recently a friend of mine are asking about ASP.net Web form vs MVC which one are better and which one should go for starting an application? I was given some opinion and discussion with him regarding the pros and cons about web form and MVC. Therefore, I decided to written it down in my blog for as references whether web form or MVC.

ASP.NET MVC

Pros
  • Provides fine control over rendered HTML.
  • Cleaner generated HTML.
  • Superior separation between UI and code.
  • Easier to unit test.
  • Can support multiple view engines.
  • By default uses RESTful intefaces for URLs – so better SEO.
  • No ViewState (this may also be a weakness).
  • Typecal size of page is small.
  • Easy integration with frameworks like JQuery.
Cons
  • Not event driven, so maybe difficult for people who know only ASP.net Webforms to wrap their minds around it.
  • Third party control library support is not that strong.
  • No ViewState(this is also a strength).
Threats
  • Bigger ramp-up and training time required for developers with no or little experience in web application development.
Opportunities
  • Allows for Test Driven Development(TDD) – it is build with TDD in mind, so its much easier to write unit test cases, mock objects and to intercept the program flow.
  • Allows for reuse of the same models to present different UIs and Interfaces.

 

ASP.NET WebForms

Pros
  • Provides very good RAD development capabilities.
  • Great designer support in VS.
  • Ease of development for data-heavy LOB applications.
  • Very rich control libraries and third party vendor support.
  • A familiar event-driven model when compared to Windows Forms development, and so easy for developers to pick up.
Cons
  • UI logic coupled with the code, and thus is hard to separate.
  • Harder to unit test, so difficult to employ TDD.
  • Heavy page sizes due to view state management.
Threats
  • Harder to adopt to various UI views despite the various frameworks available (master pages, themes, etc.)
Opportunities
  • Great at creating quick prototypes for business applications. This comes in very handy when trying to show quick Proof of Concepts to clients.

 

When to use ASP.net WebForm or MVC?

image

Posted in ASP.net | Tagged , | Leave a comment

Gridview Header and first column always show

C#:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].CssClass = “locked”;
        e.Row.Cells[1].CssClass = “locked”;
    }

html:

  <head runat=”server”>
    <title>Untitled Page</title>
    <style type=”text/css”>

div#div-datagrid {
width: 220px;
height: 100px;
overflow: auto;
scrollbar-base-color:#ffeaff;
}

/* Locks the left column */
td.locked, th.locked {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: navy;
color: white;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*IE5+ only*/
left: expression(document.getElementById(“div-datagrid”).scrollLeft-2);
}

/* Locks table header */
th {
font-size: 14px;
font-weight: bold;
text-align: center;
background-color: navy;
color: white;
border-right: 1px solid silver;
position:relative;
cursor: default;
/*IE5+ only*/
top: expression(document.getElementById(“div-datagrid”).scrollTop-2);
z-index: 10;
}

/* Keeps the header as the top most item. Important for top left item*/
th.locked {z-index: 99;}

/* DataGrid Item and AlternatingItem Style*/
.GridRow {font-size: 10pt; color: black; font-family: Arial;
             background-color:#ffffff; height:35px;}
.GridAltRow {font-size: 10pt; color: black; font-family: Arial;
             background-color:#eeeeee; height:35px;}
</style>
</head>

<div id=”div-datagrid”>
        <asp:GridView DataSourceID=”SqlDataSource1″ ID=”GridView1″ runat=”server” OnRowCreated=”GridView1_RowCreated” OnRowDataBound=”GridView1_RowDataBound”>
</asp:GridView> </div>

Posted in ASP.net, C# | Leave a comment

SQL Database physical size

If you are looking for a script that able to retrieve from select statement, below script will help you to retrieve.

SELECT physical_name,
    CASE
        WHEN is_percent_growth = 0
            THEN LTRIM(STR(growth * 8.0 / 1024,10,1)) + ‘ MB, ‘
        ELSE
            ‘By ‘ + CAST(growth AS VARCHAR) + ‘ percent, ‘
    END +
    CASE
        WHEN max_size = -1 THEN ‘unrestricted growth’
        ELSE ‘restricted growth to ‘ +
            LTRIM(STR(max_size * 8.0 / 1024,10,1)) + ‘ MB’
    END AS Autogrow
FROM sys.database_files

Posted in SQL | Tagged | Leave a comment

Debugging mode does not run in SharePoint

What you need to do is follow the steps below to try again the debugging mode

  1. Start –> Run –> Enter %systemroot%\assembly\gac –> [ENTER].
  2. From there, go up one folder, then into GAC_MSIL folder.
  3. Paste the pdb file with the DLL that you required to debug. Then run again to attach the process for debugging.
Posted in SharePoint | Tagged | Leave a comment

Override Global css from SharePoint 2010 to hide left navigation

 

If you look for hide the left navigation from SharePoint 2010, definitely you can use the below stylesheet to override the global css.

Add this code in the content editor and apply the changes:

<Style>
#s4-leftpanel
{
display: none;
}
.s4-ca
{
margin-left: 0px;
}
</style>

You able to apply this method to override other class id that you would like to change.

Posted in SharePoint, SharePoint 2010 | Tagged | Leave a comment

Using SharePoint Modal Dialog

SharePoint 2010 have introduces the new dialog framework for assist users to stay in the context of the page without navigate away from other page.

image

The JavaScript object model provides the SP.UI.ModalDialog class to work with the dialog framework. In order to work with dialog framework, first create the dialog options as below:

var options = SP.UI.$create_DialogOptions();
options.width = 500;
options.height = 250;
options.url = "/_layouts/StandardsPortal/ChangePassword.aspx";
options.dialogReturnValueCallback = Function.createDelegate(
                    null, portal_modalDialogClosedCallback);

As you can see above code, set options on width, height and the URL of the modal dialog load. If you notice, that is also initialize the call back.

You can write code below to show modal dialog:-

SP.UI.ModalDialog.showModalDialog(options);

Try to write this code into function:

function portal_openModalDialog() {
    var options = SP.UI.$create_DialogOptions();
    options.width = 500;
    options.height = 250;
    options.url = "/_layouts/StandardsPortal/ChangePassword.aspx";
    options.dialogReturnValueCallback = Function.createDelegate(
                        null, portal_modalDialogClosedCallback);
    SP.UI.ModalDialog.showModalDialog(options);
}

You can now call this JavaScript function from your custom action or from web part or from your custom page or from your custom Ribbon button. Below is the custom action XML:

<CustomAction
   Id="{F93B1F84-1DBE-4C10-82E3-2CA47346359E}"
   Title="Change Password"
   Description="Change your password"
   Sequence="1000"
   Location="Microsoft.SharePoint.StandardMenu"
   GroupId="PersonalActions"
   ImageUrl="~sitecollection/_layouts/images/menulistsettings.gif">
   <UrlAction Url="javascript:portal_openModalDialog();"/>
</CustomAction>

Notice how we invoke the JavaScript dialog:

<UrlAction Url="javascript:portal_openModalDialog();"/>    

Below is the dialog callback code (very simple actually):

function portal_modalDialogClosedCallback(result, value) {
    if (value == '1') {
        this.statusId = SP.UI
            .Status
            .addStatus("Password Changed",
               "Your password has been changed. Use it next time when you log in.", 
                true);
        SP.UI.Status.setStatusPriColor(this.statusId, "Green");
    }

    if (value == '0') {
        this.statusId = SP.UI
            .Status
            .addStatus("Password Change Failed",
                "Your password has <b>not</b> changed. Please try again.", 
                true);
        SP.UI.Status.setStatusPriColor(this.statusId, "Green");
    }

    setTimeout(RemoveStatus, 6000);
}

function RemoveStatus() {
    SP.UI.Status.removeStatus(this.statusId);
}

As you can see, I pass a single value back and now I can check and show status based on that value. You can also check for the dialog result using SP.UI.DialogResult.OK and SP.UI.DialogResult.cancel properties:

 function CloseCallback(result, value) { 
        if(result === SP.UI.DialogResult.OK) { 
            alert("OK was clicked!"); 
        } 
        if(result === SP.UI.DialogResult.cancel) { 
            alert("Cancel was clicked!");         
        } 
 }

Showing a status is very simple using the SP.UI.Status.addStatus method.

Now, after deploying when you click on the Change Password custom action

 

You get the modal popup dialog opening the Application page URL set in the dialog options:

image

To wire the Modal Dialog ‘OK’ and ‘Cancel’ code, we write the appropriate code in the ‘Change Password’ button click & ‘Cancel’ button click:

this.Page.Response.Clear(); 
this.Page.Response.Write("
<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, 1);</script>"); 
this.Page.Response.End();

If successful, you will see the following status:

image

If failed, you will see the following status:

image

Posted in SharePoint 2010 | Tagged | Leave a comment

How to copy an image from an URL to own server and resize it

private void Page_Load(object sender, System.EventArgs e) 
    {
        WebClient wc = new WebClient();


        byte[] data = wc.DownloadData("http://www.google.cn/intl/en-us/images/logo_cn.gif");


        MemoryStream ms = new MemoryStream(data);


        System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
 
       float iScale = img.Height > img.Width ? (float)img.Height / 100 : (float)img.Width / 100; 


        img = img.GetThumbnailImage((int)(img.Width / iScale), (int)(img.Height / iScale), null, IntPtr.Zero);


        MemoryStream memStream = new MemoryStream();


        img.Save(Server.MapPath("att.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg);


        memStream.Flush();
    }

 

Posted in ASP.net | Leave a comment

How to setup form library at SharePoint 2010 Foundation?

Step 1: Create Web Application

1. Access SharePoint Central Administration

clip_image002

2. Click on Application Management and then click on manage web applications.

clip_image004

3. Click on new button to create a new web site.

clip_image006

4. Leave everything as default except under Application Pool, change Select a security account for this application pool to Predefined as Network Service and then click Ok button.

Remarks: It will take for a while depend on the server performance to create a web site.

clip_image007

5. Completed create web site.

clip_image009

Step 2: Create site collections before publish InfoPath into form library.

1. Access to Application Management

2. Click on Create site collections under Site Collections.

clip_image010

3. Verify web application. If incorrect, change path

clip_image011

4. Enter title and description

clip_image013

5. Set as Default

clip_image015

6. It is depend on the requirements. As a start, you able to select under Collaboration and select for blank site

clip_image017

7. Predefine primary administrator and secondary administrator for.

clip_image019

Best Practice: Always assign to two different accounts for avoid any permission issue.

8. Quota Template is to use for control the storage size on the particulate site. For now, set as default.

clip_image021

9. Click ok and completed the site.

10. Verify the site by paste the url at IE browser.

Step 3: Publish InfoPath to SharePoint Foundation

1. Open your InfoPath form which already created by InfoPath Designer.

clip_image023

2. Click on the File tab on top of the InfoPath designer.

clip_image024

3. Select Publish Tab and Click on SharePoint Server button

clip_image025

4. Publish wizard prompt and enter URL which created in step 2 and then click next button.

clip_image026

5. Enter your password to publish into the collections sites.

clip_image027

6. Select form library and then click next.

clip_image029

7. Select “Create a new form library” – If collection sites already created a form library and required to use that, kindly to select “Update the form template in an existing form library”.

clip_image031

8. Enter Name and Description for a new form library.

clip_image032

9. Display column in your form library. You can modify it for add new column, remove or modify it. Those columns are the field in InfoPath.

clip_image033

10. Click on publish to publish the InfoPath Template.

clip_image034

11. Click Close

clip_image036

12. Verify the InfoPath whether publish into Form Library.

clip_image037

Step 4: Assign workflow into InfoPath Form Library

1. Click on Purchase Order Form

clip_image038

2. Click on Library button at the Ribbon Menu

clip_image039

3. Click on workflow setting under the Ribbon Menu

clip_image040

4. Select “Add a Workflow”.

5. Select a workflow template: “Approval – SharePoint 2010” (This is basic standard worklow)

Remarks: If looking for customization workflow, you need to use WF/SharePoint designer to create a new template and upload into SharePoint.

· Enter unique name for this workflow. This is for reusable if new document library required same workflow process.

clip_image042

6. Unchecked “Allow this workflow to be manu……” this one required user to manually submit the workflow to approver.

Checked “Start the workflow when a new item is created”.

Click next button to complete the workflow.

clip_image044

7. Predefine approver/groups/subject of email/due date/duration of tasks/ cc and etc.

clip_image046

Step 5: How to submit a form

1. Go to Purchase order form

clip_image047

2. Click on add document and filled in the form.

clip_image049

Remarks: SharePoint Foundation Server integration with InfoPath – User have to install InfoPath to access this. If user want to access without InfoPath, upgrade is required for Enterprise Version. Enterprise version features for InfoPath Services which able for user to access via Browser.

3. Submit the form and message prompt. If required password, use NT account ID and password.

clip_image050

4. You able to see the form is uploaded and status for Approval is in progress.

clip_image052

clip_image053

Step 6: Approval Process

1. Approval Login to the Purchase Order Page

2. Approval able to review document by click on the Name.

3. InfoPath form will appear a message to approval for request approval.

clip_image054

4. Open this task to process for the approval process.

5. One approve, status will change to approved.

6. If reject, status will change it to rejected and required user to resubmit again.

7. Email notification will submit when the workflow process is trigger.

8. You can able to check the history transaction by

clip_image055

clip_image057

Click on the approval link

clip_image059

Workflow history will listed all the transaction including notification.

Posted in SharePoint 2010 | Tagged , | Leave a comment

TFS in SQL Navigator for Oracle

Architecture

clip_image002

The idea of the architecture for TFS is everyone has their own workspace.

So, developers have to map their workspace from TFS and connect it to Navigator.

You will find an error as below:-

clip_image004

This means that, you don’t install the component below. Follow the step and setup for connect to TFS.

Look for  in internet for this component: Foundation Server MSSCCI Provider.msi

Install Visual Studio Team Foundation Server MSSCCI Provider.msi at your local

After finish install, follow the below step for connect to your TFS server.

1. Login to your database

clip_image006

2. Check version control browser from team coding

clip_image008

3. Check whether connect to correct TFS server

clip_image010

4. If not, add TFS server and select the correct TFS server.

5. Connect to the correct Schemes

clip_image012

6. Create a local path for your workspace from browse. After created, click Ok.

clip_image014

7. Connect to DB

8. Go to menu, Team Coding |Connection Settings

clip_image001

9. Go to menu Team Coding |Code Control Groups, click Add Group button (see below) to create a group named tfs2008

clip_image003

10. Set the group to work with the schema

clip_image005

11. We could use SQL Navigator for Oracle to check-in/check-out, and getting latest source without the reported issues.

Posted in Team Foundation Server | Tagged | Leave a comment