this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Showing posts with label Stuffs. Show all posts
Showing posts with label Stuffs. Show all posts

Monday, October 1, 2012

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

Wednesday, June 6, 2012

Print button is not working in Crystal report viewer


Crystal report is very crucial part of LOB application reporting. Most of enterprise uses Crystal Report for the reporting purpose. In case of windows platform, it has good integration with .net framework and .net provides crystal report viewer for rendering Crystal report.

From the early, VS 2005 has inbuilt integration with Crystal report version 10. We don’t need to install other component for accessing Crystal Report Viewer. It was straight forward process, for running that application on client machine we all need is installing Crystal Report runtime.

It was going good and we didn’t come across any issues till date. Some older applications were built on VS 2005 and it was running in most of windows operating system with runtime and necessary component installed. Problem arose with 64bit version, when we try to install application built on VS 2005 and using crystal report on Win 7 64bit or other later version of 64bit. In that case, we don’t able to take advantage of printing facility of Crystal report viewer.

After investigating, we found that there was problem with crystal report version10. If we upgrade our crystal report version to later on, it would work and it did.

We choose path of upgrading our solution to VS 2010, and what we found that we didn’t see any Crystal Report viewer in toolbox. It requires installed explicitly, Microsoft stops to ship that along with VS 2010.

I hope below link is worth to keep with us while upgrading to vs2010 for Crystal Report .


Hope this post will be helpful!

Tuesday, June 5, 2012

Change default time out of strongly typed dataset table adapter command.


By default when every any command executed by table adapter, its time out is 30 second. Due to heavy load of data and traffic over the network, we require increasing this default time out.
It’s very straight forward when we use code for it. In case of strongly data set it’s a bit tricky.
Firstly, you will require extending your dataset existing name space and its table adapter. In data table adapter class, you can add one method for changing this time out.
//Extend existing data table adapter class created by strongly typed dataset.
Namespace MyTableAdapters
Partial Public Class MyTableAdapter

Public Sub SetCustomCommandTimeout()
Utility.SetCommandTimeout(CommandCollection)
End Sub

End Class
End Namespace
//Set Custom Timeout to underlying command.
Public Shared Sub SetCommandTimeout(ByVal commands As System.Data.SqlClient.SqlCommand(), Optional ByVal timeout As Integer = -1)

If (commands IsNot Nothing) Then

If (timeout < 0) Then timeout = GetConfigTimeout()

For Each cmd As System.Data.SqlClient.SqlCommand In commands
cmd.CommandTimeout = timeout
Next

End If

End Sub

//Get Custom time out from web.config.

Private Shared Function GetConfigTimeout() As Integer

Dim timeOut As Integer
If Not System.Configuration.ConfigurationManager.AppSettings("CommandExecutionTimeOut") Is Nothing Then
timeOut = CType(System.Configuration.ConfigurationManager.AppSettings("CommandExecutionTimeOut"), Integer)
Else
timeOut = 0
End If

Return timeOut

End Function

Hope this would be very helpful !!

Tuesday, May 1, 2012

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!!

Wednesday, February 22, 2012

Programmatically create folder in SharePoint Document library with client object model

SharePoint 2010 has very strong client object library, with the help of client object model we can almost interact with all document related functionality from our application and can interact with SharePoint 2010.

Below is some code snippet for creating new folder in the SharePoint Document Library.

public bool CreateSPFolder(string libname, string correspondance)

{

bool bolReturn = false;

ClientContext ctx = this.GetSPClientContext();

Web web = ctx.Web;

List documentLib = ctx.Web.Lists.GetByTitle(libname);

string targetFolderUrl = libname + "/" + correspondance;

Folder folder = web.GetFolderByServerRelativeUrl(targetFolderUrl);

ctx.Load(folder);

bool exists = false;

try

{

ctx.ExecuteQuery();

exists = true;

}

catch (Exception ex)

{

bolReturn = false;

}

if (!exists)

{

ContentTypeCollection listContentTypes = documentLib.ContentTypes;

ctx.Load(listContentTypes, types => types.Include

(type => type.Id, type => type.Name,

type => type.Parent));

var result = ctx.LoadQuery(listContentTypes.Where

(c => c.Name == "Folder"));

ctx.ExecuteQuery();

ContentType folderContentType = result.FirstOrDefault();

ListItemCreationInformation newItemInfo = new ListItemCreationInformation();

newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;

newItemInfo.LeafName = correspondance;

ListItem newListItem = documentLib.AddItem(newItemInfo);

newListItem["ContentTypeId"] = folderContentType.Id.ToString();

newListItem["Title"] = correspondance;

newListItem.Update();

ctx.Load(documentLib);

ctx.ExecuteQuery();

bolReturn = true;

}

return bolReturn;

}

Monday, January 23, 2012

Fix issue HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Error with a SharePoint 2010 Web Application

Generally, such error comes when we try to browse web-application url. There could be many problems around this problem and depends on it there are different solution for it.

First most common issue around this is that, web application does not contain any site collection at web application root level url, to resolve this you can create site collection from central admin ->Application Management ->Create Site Collection. During creation of site collection, please select your web application where you would like to create.

Second scenario, if you have already site collection created and still this problem occurs. To overcome such problem you have choice to restart IIS, reattach your content database, check services on your pc whether “work station” service is started.

Hope this will help!!

Thursday, January 12, 2012

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

Cheers!!

Wednesday, January 11, 2012

Adding Footer to SharePoint 2010 Custom Master Page

When you are going to develop custom layout of your SharePoint site, it could be requirement of having footer in the page. V4 master page does not contain any options to set footer in page.

You need to add footer manually to your custom master page.

If you check your master page you will find below line

Just above that line you can add your custom footer section as below sample markup.

Copyright © 2012 Company. All Rights Reserved.

Style for above div

*Customized foooter */

#s4-customfooter{

clear: both;

padding: 10px;

color: #ffffff;

background-color: #4F5E85;

}

Hope this will help!!

Thursday, January 5, 2012

The Project Item "module1" cannot be deployed through a Feature with Farm Scope

You might have faced such error sometime during your deployment of SharePoint projects. Usually this error comes due to lack of availability of particular item in the scope. You have limited items that can be deployed in the scope of web, site, web application and farm level.

Microsoft has prepared a very nice article to list out it. You can check out here

Monday, December 26, 2011

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

Thursday, November 17, 2011

Calendar (datetime picker) type column in windows grid

Usually when we try to find some out of use column in default grid provided by .net, we are not able to do it. We require inheriting base class and then we need to put information inside of it.

Say for example, you require adding datetime picker column to your windows form grid, if you check all supported column types in grid, you won’t find such in it. We require writing custom code for it and then adding that columns in our grid control.

Here is some code for creating date time picker column, please make sure that you can add this code in separate component code and then you can access this column in whole project when ever needs.

using System;

using System.Windows.Forms;

public class CalendarColumn : DataGridViewColumn

{

public CalendarColumn() : base(new CalendarCell())

{

}

public override DataGridViewCell CellTemplate

{

get

{

return base.CellTemplate;

}

set

{

// Ensure that the cell used for the template is a CalendarCell.

if (value != null &&

!value.GetType().IsAssignableFrom(typeof(CalendarCell)))

{

throw new InvalidCastException("Must be a CalendarCell");

}

base.CellTemplate = value;

}

}

}

public class CalendarCell : DataGridViewTextBoxCell

{

public CalendarCell()

: base()

{

// Use the short date format.

this.Style.Format = "d";

}

public override void InitializeEditingControl(int rowIndex, object

initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)

{

// Set the value of the editing control to the current cell value.

base.InitializeEditingControl(rowIndex, initialFormattedValue,

dataGridViewCellStyle);

CalendarEditingControl ctl =

DataGridView.EditingControl as CalendarEditingControl;

// Use the default row value when Value property is null.

if (this.Value == null)

{

ctl.Value = (DateTime)this.DefaultNewRowValue;

}

else

{

ctl.Value = (DateTime)this.Value;

}

}

public override Type EditType

{

get

{

// Return the type of the editing control that CalendarCell uses.

return typeof(CalendarEditingControl);

}

}

public override Type ValueType

{

get

{

// Return the type of the value that CalendarCell contains.

return typeof(DateTime);

}

}

public override object DefaultNewRowValue

{

get

{

// Use the current date and time as the default value.

return DateTime.Now;

}

}

}

class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl

{

DataGridView dataGridView;

private bool valueChanged = false;

int rowIndex;

public CalendarEditingControl()

{

this.Format = DateTimePickerFormat.Short;

}

// Implements the IDataGridViewEditingControl.EditingControlFormattedValue

// property.

public object EditingControlFormattedValue

{

get

{

return this.Value.ToShortDateString();

}

set

{

if (value is String)

{

try

{

// This will throw an exception of the string is

// null, empty, or not in the format of a date.

this.Value = DateTime.Parse((String)value);

}

catch

{

// In the case of an exception, just use the

// default value so we're not left with a null

// value.

this.Value = DateTime.Now;

}

}

}

}

// Implements the

// IDataGridViewEditingControl.GetEditingControlFormattedValue method.

public object GetEditingControlFormattedValue(

DataGridViewDataErrorContexts context)

{

return EditingControlFormattedValue;

}

// Implements the

// IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.

public void ApplyCellStyleToEditingControl(

DataGridViewCellStyle dataGridViewCellStyle)

{

this.Font = dataGridViewCellStyle.Font;

this.CalendarForeColor = dataGridViewCellStyle.ForeColor;

this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;

}

// Implements the IDataGridViewEditingControl.EditingControlRowIndex

// property.

public int EditingControlRowIndex

{

get

{

return rowIndex;

}

set

{

rowIndex = value;

}

}

// Implements the IDataGridViewEditingControl.EditingControlWantsInputKey

// method.

public bool EditingControlWantsInputKey(

Keys key, bool dataGridViewWantsInputKey)

{

// Let the DateTimePicker handle the keys listed.

switch (key & Keys.KeyCode)

{

case Keys.Left:

case Keys.Up:

case Keys.Down:

case Keys.Right:

case Keys.Home:

case Keys.End:

case Keys.PageDown:

case Keys.PageUp:

return true;

default:

return !dataGridViewWantsInputKey;

}

}

// Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit

// method.

public void PrepareEditingControlForEdit(bool selectAll)

{

// No preparation needs to be done.

}

// Implements the IDataGridViewEditingControl

// .RepositionEditingControlOnValueChange property.

public bool RepositionEditingControlOnValueChange

{

get

{

return false;

}

}

// Implements the IDataGridViewEditingControl

// .EditingControlDataGridView property.

public DataGridView EditingControlDataGridView

{

get

{

return dataGridView;

}

set

{

dataGridView = value;

}

}

// Implements the IDataGridViewEditingControl

// .EditingControlValueChanged property.

public bool EditingControlValueChanged

{

get

{

return valueChanged;

}

set

{

valueChanged = value;

}

}

// Implements the IDataGridViewEditingControl

// .EditingPanelCursor property.

public Cursor EditingPanelCursor

{

get

{

return base.Cursor;

}

}

protected override void OnValueChanged(EventArgs eventargs)

{

// Notify the DataGridView that the contents of the cell

// have changed.

valueChanged = true;

this.EditingControlDataGridView.NotifyCurrentCellDirty(true);

base.OnValueChanged(eventargs);

}

}