Posts filed under ‘.net’

Add Event/Appointment in Google Calendar with Google account credential.

Google calendar is one of the best free tool for tracking your day to day appointment and reminder for your rest of schedule. There are facilities for reminder with email and sms that will enable you for preparing your next meeting/appointment.

We can leverage this tool in our any of application, we can sync our event or appointment with google calendar so one may miss reminder from application but alternatively get from google calendar.

Doesn’t it seem cool? Even implementation is simpler than it seem.

Firstly, you will need to add reference of following files.

using Google.GData.Client;

using Google.GData.Extensions;

using Google.GData.Calendar;

 

You can find those files here.

 

Below is code block for adding event in google calendar.

 

public CalendarService GetService(string applicationName, string userName, string password)

{

CalendarService service = new CalendarService(applicationName);

service.setUserCredentials(userName, password);

return service;

}

 

public static void AddEvent(CalendarService service, string title, string contents, string location, DateTime startTime, DateTime endTime)

{

Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry();

 

// Set the title

entry.Title.Text = title;

 

//Set event details.

entry.Content.Content = contents;

 

// Set a location for the event.

Where eventLocation = new Where();

eventLocation.ValueString = location;

entry.Locations.Add(eventLocation);

 

//Set starting time and end time for the event.

When eventTime = new When(startTime, endTime);

entry.Times.Add(eventTime);

 

Uri postUri = new Uri(“https://www.google.com/calendar/feeds/aslam.h.net@gmail.com/private/full”);

 

// Send the request and receive the response:

AtomEntry insertedEntry = service.Insert(postUri, entry);

}

 

Here, GetService method will take three parameters named application name, username and password.

Application name can be any name, you wish. Username is your google account name where you have configured your calendar and wish to sync with that calendar. Password is your google account password.

Method will return back calendar service object. We can use this service object anywhere for using any service associated with calendar.

 

Method AddEvent: this method will add event in any our calendar. Most of statements are formatted with comments.

There is one critical statement you need to take care.

 

Uri postUri = new Uri(“https://www.google.com/calendar/feeds/shailesh@gmail.com/private/full”);

 

 

Please note that one dynamic part, shailesh@gmail.com. It’s my calendar’s id. You can easily find your sync calendar id with following steps.

 

1)      Logon to your gmail account and click on calendar link at top bar, it will open up your calendar in new tab.

2)      On the right side, there will be section named “My Calendars”. It lists out calendars, you created. You can create more than one calendar in google calendar tool.

3)      Go to any of calendar, click on the arrow. It will show one menu. Click on “Calendar settings”.

4)      There will be one row with “Calendar Address”, most probably before last row. Just look around this row, there will be information like this.

(Calendar ID: shailesh @gmail.com)

This is the address for your calendar. No one can use this link unless you have made your calendar public

 

That’s it.

 

I hope this will enable to sync your important tasks, appointment and meeting with google calendar.

 

Happy scheduling appointment

October 1, 2012 at 5:15 am Leave a comment

Do not serialize public property or field in a class

There could be some situation where one have some properties and fields defined in the class. Most of time property are exposed as public and they can be easily accessed by object of class.

 

During the data transfer serialization of objects happens and at that time we have all the public fields and property contained in the class.

 

Some situation has special needs to prevent serializing public property or fields. Below code snippent shows how to handle such situation.

 

[XmlIgnoreAttribute]

public bool IsActive

{

get { return this.mIsActive; }

set { this.mIsActive = value; }

}

 

Have happy coding!

May 1, 2012 at 5:40 am Leave a comment

Prerequisites could not be found for bootstrapping (while upgrading from VS 2005, 2008 to VS 2010)

Latest IDE by Microsoft for .net application is VS 2010. Most of applications are upgraded to newer version of IDE, some are in the process and some are already done. The thing create problem during upgrade is that most of time targeted framework does not change, it just refer older version.

When you try to add prerequisites, you will be surprised that it will not find your older version any more. Many forums said that Microsoft has disabled it and you need to upgrade to higher version of prerequisites.

You can see that in the given below images that shows unavailability.

To resolve this issue you need to copy boots trapper files.

Older version of VS files can be found at

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

You need to copy files from above location to below location and once you copy required folders, you will be able to access those in prerequisites.

C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages

January 12, 2012 at 9:59 am Leave a comment

How to get public key token for my dll or exe?

Sometime we need to find our dll or exe’s public token when we have strongly signed out. There is a very nice tool given by .net is sn.exe

Just go to command prompt of visual studio, and type following command. Here please note that you need to set your application folder path where your dll or exe assembly is stored.

Sn – T abc.dll

This will give us public token of abc.dll like below message

Public key token is c8903c1b3f99ec16

December 26, 2011 at 6:42 am Leave a comment

Secure asp.net website URL with global.asax

Once any one has installed SSL certificate in their server, there is need to redirect old http url to https protocol. If we don’t write any custom code for redirection it will continue to browse by both of url.

There are many ways to redirection of page, we are going to take a look on global.asax file. We all are much familiar with Global.asax file in asp.net application, it handles out most of application related events.

We can use following code snippet to redirect http to https

protected void Application_BeginRequest(Object sender, EventArgs e)

{

if (HttpContext.Current.Request.IsSecureConnection.Equals(false))

{

HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri.Replace(“http://”, “https://”));

}

}

August 16, 2011 at 7:10 am Leave a comment

Redirect old page to new page with use of web.config

Recently we found that some of our old links were broken as we have changed our page name to make it seo friendly. Suddenly, over the night our site’s page rank was down. It was really embarrassed situation for all of us.

There were below reason for it.

As we have moved our server from linux to windows platform and there were no idea of page rename, and lack of technical availability to use htaccess redirection in windows platform.

After some work around it, finally I came across following things which is very good and needs to use when we rename any page and don’t want old link should be break.

Here, please not that following things will work on IIS 7.0+

First block will resolve canonical issue of prefix www before any domain name.

Second block will redirect my old page link to new mapped page.

<rule name=”Redirect to WWW” stopProcessing=”true”>

<match url=”.*” />

<conditions>

<add input=”{HTTP_HOST}” pattern=”^mydomain.com$” />

</conditions>

<action type=”Redirect” url=”http://www.mydomain.com/{R:0}” redirectType=”Permanent” />

</rule>

 

<rule name=”redirect to new java page” stopProcessing=”true”>

<match url=”^javadeveloper.html” />

<action type=”Redirect” url=”java-development-services.html” redirectType=”Found” />

</rule>

July 4, 2011 at 9:36 am Leave a comment

Allowing special character in xml with .net in built class

Recently I was finding solution to allowing special character in xml, it can be done by replacing with replaced code. You can check here

But if you are using .net then we have one inbuilt class that replaces all of the special character with replaced code and you don’t need to worry for every special character replacement.

Code sample:

XMLstring = System.Security.SecurityElement.Escape(XMLstring)

 

March 29, 2011 at 3:36 pm Leave a comment

OCR In .net with MS-Office 2007 component (MODI)

I have been just passed through requirement to implement OCR in one of my .net application. There are very less option available in .net to implement it. I thought to share with you what I have learned at that time.

In .net OCR can be done with Ms-Office component, it’s the Microsoft Office Document Imagining Library. It is required to have ms-office on your pc before you develop or run this application. This component is available in both ms-office 2003 and 2007.

Initially when we install our office, it does not install image library in our pc, we need to install it explicitly. When you start to add/remove features in your office you need to check following things should be included.

Once you have installed it, you can start to develop your application.

You can take any project type either windows or console. Now you need to add reference of Document Imaging Library to your project, that will be available in com tab of add reference dialog box. Please note down that this will be only shown if you have installed it correctly. If you don’t able to see it though you have installed, try to restart your system and then check it again.

Once you have added that com reference you can work with images and can read text from it.

 

 

January 5, 2011 at 7:32 am Leave a comment

Hide Tab Pages from Tab Control in Win forms

Recently I come to know one requirement to hide tab pages on my tab control of windows form depends on some condition.

I thought there could be some properties like Visible as we have in other controls. But surprisingly there is no such properties exist.

At the end I have only one solution to remove my tabpage from tab control. Let’s go through some code.

I have following tabControls.

myTabControl is my Tab Controls and I have following sub tabs(tab Pages) in it.

tabPage1

tabPage2

tabPage3

At index of 0, 1 and 2 respectively.

To hide my tabPage1 on my UI I have following options.

myTabControl.TabPaegs.Remove(0)

or

myTabControl.TabPages.Remove(tabPage1)

I hope this could be helpful when we have some condition for showing tabs.

August 10, 2010 at 8:45 am Leave a comment

Call customize Main method in Vb.net

If you have tried to find main method in vb.net, you would not able to find it because vb.net automatically generates that method at runtime. We don’t require writing it.  Developer who have worked with C# may find this problem most.

You can write your own main method that can be used at runtime. You can write your main method in a class or a module like below.

But you need be aware of one thing on your project properties

Application->uncheck Enable application framework. In this case, your main method will be invoked instead of automatic generated one.

July 20, 2010 at 1:49 pm Leave a comment

Older Posts


Archives

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Blog Stats

  • 8,361