Tuesday, September 14, 2010

Path way to better coding...

I’m a big fan of Joel Spolsky’s writings and last weekend I checked his article archive for some useful to read. One interesting article I found there, which is about how we can steer our development process to achieve better coding. Even though he has written this in year of 2000, it's almost valid yet.

He was discussing about 12 steps we can follow up for better coding and he named it as Joels Test

The Joel Test

  1. Do you use source control?
  2. Can you make a build in one step?
  3. Do you make daily builds?
  4. Do you have a bug database?
  5. Do you fix bugs before writing new code?
  6. Do you have an up-to-date schedule?
  7. Do you have a spec?
  8. Do programmers have quiet working conditions?
  9. Do you use the best tools money can buy?
  10. Do you have testers?
  11. Do new candidates write code during their interview?
  12. Do you do hallway usability testing?

Questions are about two options you take as answer; Yes or No.

Have a read all the article…

Monday, September 13, 2010

Software Usability...

Usability is a big thing to be bothered about in the current industry. Even though we have delivered all the functionalities well worked, how we are going to assure that customer is reaching all the functionalities and features we developed over nights to make them happy.

Found nice definitions for usability from the few articles I read…

Put User at the center of the Process
The term usability in the context of creating software represents an approach that puts the user , rather than the system, at the center of the process.

Usability And Likability
Usability is a measure of how easy it is to use a product to perform prescribed tasks. This is distinct from the related concepts of utility and Likability.

Regards

Lakmal Kankanamge

Wednesday, August 4, 2010

Path 'SVNURL' is not canonicalized; there is a problem with the client.

Few months back, we were migrating our SVN server into new machine and after the migration we all needed to Re-Locate our sources.
In that case, what we were assisted to replace old server URL with new Server URL.

As Expected Re-Locating went successfully and after that we were trying to get update the Projects Sources with the new server. But it was started throwing following error message.

Path 'https://svnservername.CompanyName.local:8443/svn/projectname' is not canonicalized; there is a problem with the client.

Error itself doesn’t tell much on issue details and was surfing internet to find the solution.

Finally found someone mentioning make all the characters in the URL into simple and try. So made the URL like this

https://svnservername.companyname.local:8443/svn/projectname.

Tried to update the source again and everything went successfully.

Regards

Lakmal Kankanamge


Wednesday, July 28, 2010

Generate .NET Code Dynamically

As I can remember, when I was starting learn to programming, writing a simple Hello World program was a big challenge, even though we had enough capable IDEs to do the programming. It’s very interesting to even imagine generate programs dynamically at run time by another program.

With Microsoft .NET CodeDom, it’s possible to generate programs, compile and run them at run time. With this framework code library, it’s possible to have virtual DLLs, Namespaces, classes, Variables, Methods and etc.

Just Imagine this is the class you need to generate dynamically,

namespace ArticlesCodeArchive

{

public class SampleClass

{

private string _property1;

private bool _property2;

public SampleClass(string tech)

{

this._property1 = tech;

this._property2 = false;

}

public string Property1

{

get { return _property1; }

set { _property1 = value; }

}

public bool Property2

{

get { return _property2; }

set { _property2 = value; }

}

}

}

Create a Namespace

public static CodeNamespace CreateNameSpace(string nameSpaceName)

{

CodeNamespace returnValue =

new CodeNamespace(nameSpaceName);

returnValue.Imports.Add

(new CodeNamespaceImport("System"));

returnValue.Imports.Add

(new CodeNamespaceImport("System.Text"));

return returnValue;

}

Method is returning a reference to a CodeNamespace object, which is representing a Namespace with provided name.

Create Class Declaration

public static CodeTypeDeclaration CreateType(string name)

{

CodeTypeDeclaration returnValue = new CodeTypeDeclaration(name);

returnValue.IsClass = true;

returnValue.BaseTypes.Add(new CodeTypeReference(typeof(Object)));

return returnValue;

}

The Class name you have to pass into the method and it will return a reference of object type CodeTypeDeclaration class, which is representing a particular .NET Class with given name.

Create a Property

public static CodeMemberProperty CreateProperty(string Name, Type propertyType)

{

CodeMemberProperty returnValue = new CodeMemberProperty();

returnValue.Attributes = MemberAttributes.Public;

returnValue.Name = Name;

returnValue.Type = new CodeTypeReference(propertyType);

returnValue.GetStatements.Add(

new CodeMethodReturnStatement(new

CodeVariableReferenceExpression("_" + Name)));

returnValue.SetStatements.Add(new CodeAssignStatement(

new CodeVariableReferenceExpression("_" + Name),

new CodeVariableReferenceExpression("value")));

return returnValue;

}

As Same as Class declaration, we have to pass Property Name and the type of the property here and method will return an object reference of type CodeMemberProperty Class, which is representing the .NET Class Property virtually.

Generate a Class

Let’s generate the class we need with all together,

public static CodeNamespace GenerateSkeleton()

{

CodeNamespace returnvalue = CreateNameSpace("ArticlesCodeArchive");

CodeTypeDeclaration generatedType = CreateType("SampleClass");

returnvalue.Types.Add(generatedType);

generatedType.Members.Add(CreateProperty("property1", typeof(string)));

generatedType.Members.Add(

new CodeMemberField(typeof(string), "_property1"));

generatedType.Members.Add(CreateProperty("property2", typeof(string)));

generatedType.Members.Add(

new CodeMemberField(typeof(string), "_property2"));

return returnvalue;

}

public void GenerateCode()

{

CodeNamespace cns = GenerateSkeleton();

return cns.ToString();

}

Now we have generated the class we need and to make sure everything is ok, you just write the text coming from GenerateCode() method to a file. And it will exactly match with the class we mentioned at the start of this article.

Compile the Generated Class

Now it’s time to working on compiling the class generated at runtime. As same as class generation, compilation is also going to be done at runtime.

public Assembly CompileCode()

{

CodeNamespace ns = GenerateSkeleton();

string lcCode = GenerateCode("C#", ns);

ICodeCompiler loCompiler = new CSharpCodeProvider().CreateCompiler();

CompilerResults loCompiled = GetCompiler(lcCode, loCompiler);

if (loCompiled.Errors.HasErrors)

{

string lcErrorMsg = "";

lcErrorMsg = loCompiled.Errors.Count.ToString() + " Errors:";

for (int x = 0; x <>

lcErrorMsg = lcErrorMsg + "\r\nLine: " +

loCompiled.Errors[x].Line.ToString() + " - " +

loCompiled.Errors[x].ErrorText;

//MessageBox.Show(lcErrorMsg + "\r\n\r\n" + lcCode,

// "Compiler Demo");

return null;

}

Assembly loAssembly = loCompiled.CompiledAssembly;

Return loAssembly;

}

At the end of the compilation, you can have compiled assembly and this is not an assembly physically exists.

How to use a virtual assembly

After generating the Assembly for the virtual class implementation, it’s time to use it at runtime. This class won’t be alive to use later or after a particular session of the application, because all these things are happening here, is virtual. Anything you need to keep for the later use, you will have to save them purposely in the code.

public void UseVirtualClass()

{

Assembly loAssembly = CompileCode();

object loObject = loAssembly.CreateInstance("ArticlesCodeArchive.SampleClass");

object loResult = null;

loResult = loObject.GetType().InvokeMember("property1", BindingFlags.DeclaredOnly |

BindingFlags.Public | BindingFlags.NonPublic |

BindingFlags.Instance | BindingFlags.SetProperty, null, loObject, new Object[] { "This is the value for propert1" });

loResult = loObject.GetType().InvokeMember("property2", BindingFlags.DeclaredOnly |

BindingFlags.Public | BindingFlags.NonPublic |

BindingFlags.Instance | BindingFlags.SetProperty, null, loObject, new Object[] { "This is the value for propert2" });

}

That’s all, now we have assigned values for an object of the class that what we generated dynamically and all these things are happening at runtime.

Lakmal Kankanamge

Friday, February 26, 2010

Office 2007 Upgrade In 2003 server has failed SharePoint....


Monday I heard from one of our customer that their SharePoint site is not working and give an error like

"Server error: http://go.microsoft.com/fwlink?LinkID=96177". That's all it says....

So I was googling to find some thing useful to overcome this and there were lots suggestions online too.

Most of the suggessions were asking to Run SharePoint Product And Technologies Upgreade and then after that things should be ok.....

But SharePoint Product And Technologies Wizard was stucking at step 9 and It was running more than a whole day, but I didn't stop it and let it to run. But finally found it is not going to stop and I stoped it.

Then fortunately found blog post asking to run following command...

stsadm –o upgrade –inplace –url Central_Administration_URL –forceupgrade

And this did the the trick for me..... it saved my days of time...... . Thanks for orginal Poster again.

Lakmal

Monday, August 3, 2009

SharePoint Task List Form View Settings

In SharePoint Task, we are having three views, New Task View (Where you initiate a new task) , Edit Task View(Where you update an exsisting task) and Task Display View (Just View a Task Details). In each view, you will need, particular fileds to be viewed, but some fields no to be in there.

I was also having same senario to be implemented in our intranet, Some fileds won't need t0 be view New Task entering view, but those fileds need to be in task editing view and so on so on.

In case i found a usefull article which describes how to achieve that what I was looking for....

This is the link...

Regards

Lakmal Kankanamge


Sunday, May 3, 2009

How to Find Start Date and End Date of a Week in given Date

This is some thing i was really working hard on to find out. And it is a common thing we might need most of the time. Suppose we need to find the Start Date and End date of this week. Only thing I can reach programatically is Current Date. In C# it's

DateTime currentDate = DateTime.NOW;

Here is the code snippet to find the Start Date and Last Date of this week.

DateTime currentDate = DateTime.Now;
int week = myCal.GetWeekOfYear(currentDate , System.Globalization.DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, DayOfWeek.Monday);
DateTime BeginingOfYear = new DateTime(DateTime.Now.Year, 1, 1);
System.Globalization.Calendar D = System.Globalization.CultureInfo.CurrentCulture.Calendar;
DateTime Weeks = D.AddWeeks(BeginingOfYear, Convert.ToInt32(week));

DateTime FirstDayOfWeek = Weeks.Subtract(new TimeSpan((int)Weeks.DayOfWeek, 0, 0, 0));

DateTime LastDayOfWeek = FirstDayOfWeek.AddDays(7);

Here We can Replace the current Date with the Date, Date that you have given.

Regards

Lakmal Kankanamge

How to Upload Files to SharePoint Doc Library...

I found this code snippet from a SharePoint Forum thread, It is about How to upload Files into SharePoint Document Library Using SharePoint API. Credit Should to original developer.
using (SPSite siteCollection = new
SPSite(url))

{
using (SPWeb spWeb = siteCollection.OpenWeb())

{

SPList spList = spWeb.GetList(url);


string fileName = "XXXX";

FileStream fileStream = null;
Byte[] fileContent = null;
try

{
string docPath = XXXX; //physical location of the file

fileStream = File.OpenRead(docPath + fileName);

fileContent = new
byte[Convert.ToInt32(fileStream.Length)];

fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));

spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true);

spList.Update();

}
catch (Exception ex)

{

}
finally

{
if (fileStream != null)

{

fileStream.Close();

}

}

}
Regards

Lakmal Kankanamge.

Friday, April 24, 2009

How to Start SharePoint Development....

I found simple article on this, and it says essential you need to know as new comer for SharePoint development. Here I copied that and paste here, just to read when I need.


The core SharePoint Services platform is comprised of more than 3000 API's. The most fundamental of these are found in the Microsoft.SharePoint namespace. The classes in this namespace will be used in virtually every Web Part and application development effort, so this is a good place to start.

The four key classes you'll need to become familiar with first are SPContext, SPSite, SPWeb, and SPUser. The SPContext class represents the context of an HTTP request in SharePoint Services. The SPSite class represents a collection of sites, including the top-level site and all children sub-sites. The SPWeb class is used to represent a single site in SharePoint. And, the SPUser class is used to represent a single user. Using these classes together lets you access virtually all information about sites and users, both in and out of the current site context.

In most situations, you'll need to know in what site context your code is currently running. To obtain this information, use the following code:

SPWeb web = SPContext.Current.Web;

If you are interested in retrieving the current site collection, use this code:

SPSite siteCollection = SPContext.Current.Site;

And if you need to access a site collection for a different context, you can use the following approaches:

SPSite siteCollection = new SPSite( "http://yourdomain/sites/hr" );

or

SPSite siteCollection = new SPSite( siteGUID );

Many times you'll want to obtain the current user for the current site context. Give this a try:

SPWeb web = SPContext.Current.Web;
SPUser currentUser = web.CurrentUser;

If you want to use some of what we learned above in a custom Web Part development effort, your code may look something like the following:

protected override RenderContents( HtmlTextWriter writer )
{
// Obtain context of current site and user.
SPWeb web = SPContext.Current.Web;
SPUser user = web.CurrentUser;

// Display the current users name.
writer.WriteLine( "Greetings: " + user.Name );
}

Obviously, this is a very basic example, but I hope it gives you a clear idea of how to use the current site context to obtain information about the site and user for which your code is executing.

To Original Article

Regards

Lakmal Kankanamge

Wednesday, April 22, 2009

SharePoint Resourses

These days, I'm experiencing the excellent of SharePoint and here it is few Sharepoint resources I found while I'm searching on

http://blog.sharepointhosting.com/Downloads/SharePoint-Tutorials.aspx
http://www.fpweb.net/sharepoint-hosting/free-sharepoint-tutorials.asp
http://www.sharepoint-videos.com/
http://blog.rafelo.com/2008/06/exposing-and-creating-hidden-sharepoint.html
http://blog.rafelo.com/2008/06/exposing-and-creating-hidden-sharepoint.html
http://www.sharepoint-tips.com/
http://sharepointobjectmodel.blogspot.com/
http://blogs.msdn.com/sharepoint/ - Microsoft SharePoint Team Blog
http://nathan.blenke.com/articles/creating_a_sharepoint_2007_theme/
http://msdn.microsoft.com/en-us/office/aa940989.aspx
http://www.worldofasp.net/tut/UpdatPanelError/Handling_and_Customizing_UpdatePanel_Errors_Gracefully_260.aspx
http://blog.visualstudioteamsystem.com/post.aspx?item=23 - SharePoint Development and Programming
http://rshelton.com/Tags/How%20to/default.aspx
http://msdn.microsoft.com/en-us/office/aa940989.aspx - Sharepoint Videos
http://office.microsoft.com/en-us/help/FX100485361033.aspx?pid=CL100605171033 - SharePoint Course with Audio Explanation.
http://www.slideshare.net/Magganpice/introduction-wss-3-and-moss-2007
http://blogs.msdn.com/sridhara/archive/2008/05/24/digging-into-why-sharepoint-navigation-apis-wouldn-t-work-on-sites-using-collaboration-or-publishing-site-definition.aspx - Navigation Programming
http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3 -- Integrate ASP.NET AJAX with SharePoint

http://www.toddbaginski.com/blog/archive/2007/12/26/how-to-programmatically-customize-site-navigation-in-wss-3.aspx - Customize Navigation

http://www.sharepointdevwiki.com/display/public/Where+to+start+with+SharePoint+Development -- Where to start sharepoint development

http://www.sharepointdevwiki.com/display/public/Creating+a+List+programmatically+using+the+object+model -- Sharepoint Code Snippet

http://www.sharepointkings.com/2008/08/create-custom-listviewwebpart.html - Customer List View

http://www.sharepointkings.com/

Web Service Examples
http://blogs.msdn.com/arpans/archive/2007/07/24/sharepoint-web-service-example-grabbing-wiki-content.aspx
http://blogs.msdn.com/ericwhite/archive/2009/01/06/getting-started-with-sharepoint-wss-web-services-using-linq-to-xml.aspx
http://www.csharphelp.com/archives4/archive602.html
http://www.developer.com/tech/article.php/3104621
http://www.sharepointdevwiki.com/display/public/SharePoint+Web+Services
http://www.infoq.com/articles/swanson-moss-web-services


Regards

Lakmal

Sunday, March 22, 2009

ASP.NET Required Field Valuator Causes problems in Tab Container

Normally with ASP.NET Tab Container we manage to keep few Data Forms in several Tab Panels. For example, One Tab Panel has User adding Form and other one has Customer Adding Form.

In Add User View We have Few Required Filed validate controls to validate few fields and in same way Add Customer Form Also having few Required Field Validate Controls to validate some user input fields.

Add User Form and Add Customer View...







The Problem I faced is like, when we submit the Add User form with user information, the Required Field Validate Controls in Add Customer Form are also fired. Then as the result, nothing is happened. Finally I found the solution for this after browsing the internet few minutes.

We need to have value for ValidationGroup Property in the Required Filed Validate Controls and for the same form every Validate Controls should have same value for Validation Group Property. And also make sure to set ValidationGroup property for the button in the form as the same value as the form's Validate Controls.


Then what happens I like, when the button press, it only validates Controls which are in the Same Group as it's ValidationGroup Property.







Cool everything went successfully.

Lakmal Kankanamge.