Tuesday, December 30, 2008

Exception from HRESULT: 0x80040E14

Recently in SharePoint server I got an error when trying to do almost any action.
The error was Exception from HRESULT: 0x80040E14.
After sometime I did find out, that my C drive has gone out of disk space, and that caused SQL transaction log creation failure which resulted this error.
So freeing up more space on C drive solved my problem.
You will be able to get more details of the error by checking SharePoint log files.

Saturday, December 06, 2008

Planning to Buy a Vehicle?

Thought to share some expensive and valuable information that might help you if you are planning to buy a vehicle. Lookout for two main things.
1. Quality of the Vehicle
2. Legal Side of the Vehicle

Although most of the things I mention in this are specific to Sri Lanka I definitely know there are similar things to check in other countries as well.

1. Quality of the Car
If you are buying a brand new vehicle this is not required because the company will give you the details technical overview and will also give you a warranty.
But if you are going for a used vehicle then you have to check for its quality. Anyway I am not that good in the technical side so you have to rely on the knowledge that you have or someone who knows better.

2. Legal Side of the Vehicle
This is one area most people are not paying that much interest. But this is the most important side, imagine a vehicle that you buy having problems with its documents, If that happens you wont be able to transfer it to your name with ease. Sometimes you even might need to go to courts. If that happens you face the difficulty when selling as well because no one would buy a vehicle from you that you don't own. Further more I advice you to check the vehicle documents because if you buy a technically unfit vehicle you can go to a mechanic and get the vehicle repaired after spending some time and money. But if documents are not good then it will be a big issue.
So what are these documents that you have to look for?

1. Certificate of Registration (CR)
This certificate will have all the details of the vehicle such as Make, Model, Year of Manufacture, Registration Number, Chassis Number, Engine Number, Present Owner, Absolute Owner, Previous Owners, Etc.
All of these are important to check, but for a successful legal transfer of ownership to you present and absolute owners are important. Always it is better to buy a vehicle from the person mentioned in the present owner field. Because the vehicle is owned by him. There are cases which people will keep vehicles with open papers.
Open Papers means that the owner will not get the vehicle transferred to his name, but he will get a set of forms filled from the seller and keep with him.
For example if Mr. ABC is buying a vehicle from Mr. STUV (Mr. STUV is the current owner in the CR). Mr. ABC will keep the transfer documents signed by Mr. STUV after doing the payments to Mr. STUV, but he will not fill them or submit them to the Department of Motor Vehicles for registration.
One advantage of open papers is the number of owners will be lesser.
One disadvantage of this is, if buyer needs to transfer the vehicle to his name he will not be guaranteed that the transfer will happen smoothly since his transferee will be an unknown person. For example in the above case if Mr. ABC is going to sell the vehicle to Mr. XYZ and if Mr. XYZ is needing to get the vehicle transferred to his name the legal transferee will be Mr. STUV who is unknown by Mr. XYZ. In which case while the transfer process is happening problems might arise.
Absolute owner - In normal case this field should be empty. If this is filled with some name that means the vehicle is on a finance or lease. In this case you cannot buy directly from the current owner. That is because when the absolute owner is superior to the current owner. So you will be needing a no objection letter from the absolute owner.
Also note in either case a company is printed under Current Owner or Absolute Owner you will be needing a no objection letter from the company in a company letter head, with the emboss seal and signed by a rightful director of the company.

2. Vehicle Identity Card (VID)
All the English number registered (HE, KA, KC, ...) vehicles will have a VID. you will be requiring this VID to carry out any legal things on the vehicle (Transferring the vehicle to you).
This is only applicable to English numbered vehicles since it is issued new.

If you follow these I think you would be able to buy a vehicle and live peacefully.

Visual Studio not Showing Errors

Is your Visual Studio showing error line numbers and respective pages while you develop?
If not read on, recently I came up to a machine which was having Visual Studio error. Visual Studio was showing errors when a project is compiled but the error details (error code line number, error file) which we can use to identify the error are not displayed.
After trying out several things found the cause of it and thought to share it.
The problem was not with the project but with the path the project was kept.
In the machine the failing project was stored under a folder which was having parenthesis or brackets "(".
For example the solution path was like C:\ProjectsA(V1)\MyProj\.
The (V1) part was confusing Visual Studio making it stop displaying the error details.
If you also have the same problem simply remove the brackets by renaming the folder and reload your project to Visual Studio from the new path. The error details will be shown correctly.

Friday, November 21, 2008

Regular Expressions

In the resent past I had to write some simple regular expressions.
So thought of sharing them with you.

An EMail Address Validator

^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}[0-9]{1,3})(\]?)$
This will validate the entered EMail address.

A Password Validator

(?=.{6,})[a-zA-Z]+[^a-zA-Z]+[^a-zA-Z]+[a-zA-Z]+
This will validate the password to have at least 1 alphabetic character and 1 numeric digit, and altogether the password will be more than 6 characters long.

A Telephone Number Valdator

\d{4}\s\d{3}\s\d{6}
This will expect the telephone number to be in international format. For example (0094 777 123456).

A Simple Length Validator

[\s\S]{1,200}
This will allow only only 200 or lesser characters for input.


A Length Validator Which Works With Linefeed (Return, Enter)

^(.\n){0,500}$
This will validate and allow only 500 input even in a multi line field when linefeed (enter) is used in between.

A Date Validator

(0[1-9]1[012])[- /.](0[1-9][12][0-9]3[01])[- /.](1920)\d\d

This will check for the date validness. The date format should be mm/dd/yyyy to correctly validate by this.

If the date format is required as yyyy/mm/dd then use the following.

(1920)\d\d[- /.](0[1-9]1[012])[- /.](0[1-9][12][0-9]3[01])

Following are some good sites that you can refer for regular expression help.

http://www.visibone.com/regular-expressions/

http://books.google.lk/books?hl=en&id=NYEX-Q9evKoC&dq=Regular+expressions&printsec=frontcover&source=web&ots=qok1lUQubw&sig=XVd8_Z3hM_CWqk5r9dupyAWIllk&sa=X&oi=book_result&resnum=6&ct=result#PPP1,M1

http://regexlib.com/CheatSheet.aspx

Monday, November 17, 2008

Installing HyperV Integration Services

I think at least some of you might have started using Hyper V.
Did you feel how difficult to move from your Host Operating System (OS) to Guest OS (You have to click some keyboard combinations to move in and out).
To make our life easier you can install HyperV Integration Services to the guest OS.

To install, after starting your virtual machine click on the Action menu and click Insert Integration Services Setup Disk. This will start the installation process. After this finishes you no need to click key sequences to go back and forth among the OSs.
This will also install the required components so that the virtual machine will be able to communicate with local area networks and internet.
Please note that you need to install the Integration Services in each and every virtual machine separately.

Thursday, November 13, 2008

Google Video Chat

Check out the new Google Video chat.
Now you can video chat using GMail.

http://mail.google.com/videochat

Hyper-V

Hyper-V is the name for the next generation hypervisor-based server virtualization technology from Microsoft.
This is included in Windows Server 2008 as a role and enables you to create and manage virtual servers or machines.
A free version of this also available which is named as Microsoft Hyper-V Server 2008. This is a Windows core having only the Hyper-V functionality enabled.
If interested better visit the following sites.
http://en.wikipedia.org/wiki/Hyper-V
http://www.microsoft.com/windowsserver2008/en/us/hyperv-overview.aspx
http://www.microsoft.com/windowsserver2008/en/us/hyperv-faq.aspx

Monday, November 10, 2008

Enabling Forms Authentication in SharePoint

Recently I needed to change the authentication of one of the application that I did using SharePoint to forms. I needed to authenticate users using Active Directory (AD). Even there are many sources explaining how to do it I found most of them are not full. So thought to put an article my self.
The default authentication method of SharePoint is Windows. It will use a window to get the user information while logging in.

To change the authentication first you need to login to the Administrator site.

Now select Application Management and click on the link Authentication Providers under Application Security.

In the Authentication Providers screen first make sure the correct web application is selected. If not, select the correct application using the drop down in the top left corner of the page.
After selecting the correct application click on the Default zone (Please note that here I am going to change the default zones' authentication. If you are to change in another zone simply select the required zone).

In the Edit Authentication page select Forms as the Authentication Type then in Membership Provider Name type AD, which we are to setup later. Then click the Save button.

As of the result of changing the authentication providers the Web.Config file will be changed accordingly automatically. But this is not enough we need to enter the membership provider details ther in site Web.Config file and Administrator site Web.Config files.
To do the necessary changes open both Web.Config files. Both files needed to be updated with the same information.

1. In the connection strings section add the following line.
This specifies the connection string to the AD. (Please note that my full computer name is 'ironone-ms-t01.MS.TEST' and my domain is 'MS.TEST'. You definitely need to change them according to your domain details.

2. Inside System.Web add a membership provider by entering the following text.
You should change the details of the connection according your settings but make sure you do not change the name from 'AD' to anything else, otherwise it will not work.
Application Web.Config
SharePoint Administration Site Web.Config
Save both Web.Configs and do an IIS reset.
Go back again to the administration site and select Application Management. Now select Policy for Web application under Application Security.
After making sure that the correct web application is selected, click on Add Users.
Select the Default as the zone and click next.
When choosing users type the full user name preceding AD:. For example to add administrator type AD:Administrator. Under the permission section select the Full Control - Has full control check box and click Finish.
As the final step you have to change the site collection administrators. For this click on Site Collection Administrators under SharePoint Site Management in Application Management.
After verifying the selected application enter Primary Site Collection Administrator as AD:Administrator. If you want you can fill in Secondary Site Collection Administrator as well. After finishing click Ok.
Now go back to the site and try to login, you will see that the traditional windows login page is replaced with a simple login web page. Since this login page is too simple I did some improvements to the login page and created my own one as you can see below.

Thursday, October 23, 2008

Correcting the error at User Control

Recently I got an error in an user control which I used to create users in Active Directory. This user control started to fail in SharePoint after deploying it in to a different server. It threw the following error,

  • Exception has been thrown by the target of an invocation.

The Inner Exception was

  • Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

After a bit of a struggle I found that the error was due to inappropriate setting in Web.Config file.

To correct it set identity impersonate to false.

<identity impersonate="false" />

Sunday, October 05, 2008

Creating an Excel Sheet using .Net

In this entry I will show how you can create a Microsoft Excel file using .Net.

// Create the Excel Application object.
ApplicationClass ExcelApp = new ApplicationClass();
// Set the visibility of the application.
ExcelApp.Visible = true;
// Create a new Excel Workbook.
Workbook ExcelWorkbook = ExcelApp.Workbooks.Add(Type.Missing);
// Create a new Excel Sheet.
Worksheet ExcelSheet = (Worksheet)ExcelWorkbook.Sheets.Add(ExcelWorkbook.Sheets.get_Item(1), Type.Missing, 1, XlSheetType.xlWorksheet);
try
{
// Loop for 10 rows.
for (int rwCount = 1; rwCount <= 10; rwCount++)
{
// Loop for 3 columns.
for (int clmCount = 1; clmCount <= 3; clmCount++)
{
ExcelSheet.Cells[rwCount, clmCount] = "This is Row - " + rwCount + " Column - " + clmCount;
}
}
// Save the Excel sheet.
// The @ symbol makes the string to contain any special characters inside the string without breaking the string.
ExcelApp.Save(@"C:\Projects\Ex.xls");
}

Accessing Data in an Excel File using .Net

In this article I will show how you can open Microsoft Excel files using .Net.
You can use OLE objects to access data in Excel files as of you are accessing SQL Server data using SQL objects.

// Create an OLEDBConnection to connect to the Excel file.
// I'm getting the required file by using a file dialog.
// The @ symbol makes the string to contain any special characters inside the string without breaking the string.
OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName.ToString()+ @";Extended Properties=""Excel 8.0;HDR=Yes;""");
// Open the connection.
dbConnection.Open();
// Create a command object to work on the data.
// Note that I have given the sheet name as [Sheet1$] to retrieve data from that named sheet in the particular Excel file.
OleDbCommand dbCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", dbConnection);
// Creating a data reader to read data.
OleDbDataReader dbReader = dbCommand.ExecuteReader();
// Get the position of the column Desc 1.
int SearchingItem = dbReader.GetOrdinal("Desc 1");
// Read through the data.
while (dbReader.Read())
{
// Traverse through all the data columns.
for (int i = 0; i <>
{
ExcelSheet.Cells[CurrentRowCount, i + 1] = dbReader.GetValue(i).ToString();
}
}

Sunday, September 21, 2008

Creating a Web Part to use with SharePoint

Creating a web part for SharePoint consists of several steps.
1. Create a user control.
2. Create the web part DLL to hold the user control.
3. Add user control and web part to SharePoint and make the web part safe.
4. Add the web part to the web parts gallery.
5. Finally add the web part to the page.
Lots of steps ha, don’t worry we’ll do step by step.

1. Create a user control.
a. Start Visual Studio and click on File -> New -> Web Site.

b. Select ASP.NET Web Site as the template, select C# as the language, and give a file system location and a name (prjFirst) for the project before pressing Ok. c. Now we need to add a page to write our code. To do that, right click on top of the project and click on Add New Item....
d. Select Web User Control as the template, select the language as C#, give a name for the user control (ucFirst) and ensure that Place code in separate file check box is checked before pressing Ok. e. Now you need to use the required web controls and write the code required in the appropriate files. For this demonstration I will put a label and a button only. When the button is clicked I will display a greeting message in the label.
f. After creating the controls and naming them as required I need to import Microsoft.SharePoint.dll since I am going to access SharePoint object model. To do this first we need to refer this dll. Right click on the project and click on Add Reference..., select the Browse tab and go to folder C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI and select Microsoft.SharePoint.dll to add the reference to the project. If your machine doesn’t have a SharePoint installation then you need to copy this file from a SharePoint installed machine to your machine and refer it.
g. After coding for the button click my code looks like this. h. Now build and see if the page is having any errors. If no errors step one is done.

2. Create the web part DLL to hold the user control.
a. Start another instance of Visual Studio and click File -> New -> Project....

b. Select Class Library as the template under C# project type and give a location and a name (clFirstWebPart) before clicking Ok. c. Right click and delete the Class1.cs file since we would like to create a new class with a meaningful name.
d. Now right click on the project and click on Add -> New Item..., then select Class as the template and give an appropriate name (csFirstWebPart.cs) and click Add. e. Now you need to refer System.Web namespace. To do so right click on project and click ok Add Reference..., then select the System.Web and click Ok. f. After inheriting the class from the WebPart override the CreateChildControls method to create a user control and load the user control we create earlier in step 1.
We are loading the user control file (ucFirst.ascx) from the SharePoint UserControls folder which we are to copy later. g. Now build the project by right clicking on project and selecting Build. If no errors occur then that means we have completed step 2 as well.
3. Add user control and web part to SharePoint and make the web part safe.
1. Now we have a user control and a web part dll which loads the user control. In order to use this in SharePoint we need to add these to SharePoint. This has 3 tasks to be done in the SharePoint Server machine.
a. Adding User Control files.

i. Go to the location that you created the user control project in step 1 and copy the 2 files of the user control (ucFirst.ascx and ucFirst.ascx.cs). ii. Go to the root folder of the web site (C:\Inetpub\wwwroot). Now find the folder named UserControls and paste the copied two files there. Notes –
· I’m trying to put the newly created web part to the default web application. So I am using C:\Inetpub\wwwroot\UserControls folder. If you need to use this web part then you needs to use the appropriate folder. For example if I am to use this in the web application http://ironone-ms-t01:16173/ then I have to create UserControls folder in C:\Inetpub\wwwroot\wss\VirtualDirectories\16173. To find the correct location of your web application use IIS Manager web site properties page. · If the UserControls folder doesn’t exist you can create it there.
b. Adding Web Part DLL.
i. Go to the location that you created the web part DLL project in step 2 and copy the output DLL file (clFirstWebPart.dll) of it. ii. Go to the root folder of the web site (C:\Inetpub\wwwroot). Now find the folder named bin and paste the copied file there. Notes –
· I’m trying to put the newly created web part to the default web application. So I am using C:\Inetpub\wwwroot\UserControls folder. If you need to use this web part then you needs to use the appropriate folder. For example if I am to use this in the web application http://ironone-ms-t01:16173/ then I have to create bin folder in C:\Inetpub\wwwroot\wss\VirtualDirectories\16173. To find the correct location of your web application use IIS Manager web site properties page. · If the bin folder doesn’t exist you can create it there.
c. Making the web part a trusted web part.
In order to use the web part we need to make the web part a trusted web part. To do this there are two ways,
1. Put an entry to the web.config file of the application.
2. Give the dll a fully trusted name and putting it to GAC.
I will be using the first method. Make a backup of the web.config file located in the C:\Inetpub\wwwroot and open it. Then add an entry to the SafeControls section. The easiest way is to copy the last line and paste it at the end and changing the Assembly and the Namespace to the dlls’ name (clFirstWebPart). Save the config file and to be in safe side do an IIS reset by typing IISReset in the Run Window.


4. Add the web part to the web parts gallery.
a. Open an Internet Explorer and browse to the site which you need to add the web part. Then click on Site Actions -> Site Settings -> Modify All Site Settings.
b. Click on Web Parts under Galleries in the Site Settings page to open the Web Part Gallery. c. In the web part gallery page you will see all the added web parts. But not our one. So we need to add that here. To do this click on New button. Note –
The files with .dwp extension are Windows SharePoint Services 2.0 web parts.
The files with .webpart are the new Windows SharePoint Services 3.0 web parts.
d. This list will have the newly added web part (clFirstWebPart.clFirstWebPart). Check the check box in front of it and click on Populate Gallery. e. Now our new web part will appear in the Web Part Gallery. This is enough but it is always better to change some properties of the web part. So open up the web part property page by clicking on the Edit button. Change the Title, Description and the Group of the web part and press Ok. f. Remember that we need to test the web part before we add it to a web page. To do this simply click on the web part. g. If you are also having the default settings then you will definitely get an error of request for the permission of type.... This is because we didn’t change the SharePoint trust level. To change this I will use the easy way of changing the trust level in the configuration file to full though the best way is to create a trust file.
Open the web.config file at C:\Inetpub\wwwroot and find the entry and change the trust level to Full. Do an IISReset and refresh the internet explorer page. Now the web part will be displayed to you.

5. Finally add the web part to the page.
Now our newly created web part is available for us to use. We’ll now add it to a page.
a. Open the required web page in the internet explorer and click Site Actions -> Edit Page to start editing mode.

b. Now on any web part zone click ‘Add a Web Part’ button. c. Among all the web parts listed select the web part that we have created (First Web Part), select the check box in front of it and click the Add button. You will see the web part appearing on the page.
d. To finalize the page click Publish button on the page. e. Click on ‘Click Me’ button and see the output. Even though adding a new web part was bit of a process, after adding doing changes to it is not that difficult. What you have to do is change the ascx and ascx.cs files and copy the new ones to the UserControls folder. I have simply changed the message to a new one using this method.