Wednesday, January 11, 2012

Populate the InfoPath 2007 Repeater sections with data from secondary data source


I had a requirement to populate the questions answer section into a InfoPath 2007 form at runtime, in which data will come from custom SharePoint list.

There were following fields for each question:
Question Text
CheckBox as answer
Textbox (If required)

Now after populating them we need to save all the answers into form. But here we are not sure how many questions will be there as they are auto populated from SharePoint List so we cannot save each answer into seperate field into form, and I used delimited text for this pupose.
vb.Net Code:

Code to popluate the questions at runtime:
[ Edit flag is used to control the repeater section insert, remove functions as these sections get populated at runtime so user will not have option to inset or remove any section. For this purpose I had to create a flag for a rule which will disable these functions when my flag is false ]

Dim editFlag As IXMLDOMNode = thisXDocument.DOM.selectSingleNode("/my:TMS/my:GeneralChecklistGroup/my:EditFlag")
editFlag.text = "1"

Dim xDocumentQA As IXMLDOMDocument2 = DirectCast(thisXDocument.GetDOM("Check List Questions"), IXMLDOMDocument2)

xDocumentQA.setProperty("SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution""")

Dim nodeRoot As IXMLDOMNode = xDocumentQA.selectSingleNode("dfs:myFields")

If nodeRoot.childNodes(0).childNodes(0).attributes(1).text = "1" Then

myQAGroup.childNodes(1).childNodes(1).text = " " + nodeRoot.childNodes(0).childNodes(0).attributes(0).text 'Text;

Else

myQAGroup.childNodes(1).childNodes(1).text = nodeRoot.childNodes(0).childNodes(0).attributes(0).text 'Text;

End If

myQAGroup.childNodes(1).childNodes(5).text = nodeRoot.childNodes(0).childNodes(0).attributes(2).text 'TextBoxRequired

myQAGroup.childNodes[1].childNodes[11].text = nodeRoot.childNodes[0].childNodes[0].attributes[4].text 'ID

Dim intCtr As Integer = nodeRoot.childNodes(0).childNodes.length - 1

For i As Integer = 0 To nodeRoot.childNodes(0).childNodes.length - 2

Dim myQAInsertSection As IXMLDOMNode = thisXDocument.DOM.selectSingleNode("/my:TMS/my:GeneralChecklistGroup/my:Questions/my:QuestionsSection")

thisXDocument.View.SelectNodes(myQAInsertSection, Type.Missing, Type.Missing)

thisXDocument.View.ExecuteAction("xCollection::insert", "QuestionsSection_140")

If nodeRoot.childNodes(0).childNodes(intCtr).attributes(1).text = "1" Then 'IsOption

myQAGroup.childNodes(3).childNodes(1).text = " " + nodeRoot.childNodes(0).childNodes(intCtr).attributes(0).text 'Text

Else

myQAGroup.childNodes(3).childNodes(1).text = nodeRoot.childNodes(0).childNodes(intCtr).attributes(0).text 'Text

End If

myQAGroup.childNodes(3).childNodes(5).text = nodeRoot.childNodes(0).childNodes(intCtr).attributes(2).text 'TextBoxRequired

Iterate through InfoPath 2007 Repeater Table to get the values Programatically

I had a task to iterate through the repeater table of InfoPath 2007 form and get all the values entered by user on submit.

Here is a vb.net code

Imports Microsoft.Office.InfoPath

'' ********** Upload multiple attachments **************
Public Sub btnUploadAllAttachments_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

Dim xPathNavigator As XPathNavigator = MainDataSource.CreateNavigator()

Dim rows As XPathNodeIterator = xPathNavigator.Select("/my:ShowCauseForm/my:ShowCauseDetails/my:AttchmentsTable/my:AttachmentRow", NamespaceManager)

While rows.MoveNext()

Upload(rows.Current.SelectSingleNode("my:Attachment", NamespaceManager).Value, "/my:ShowCauseForm/my:ShowCauseDetails/my:HyperLinkSection/my:AttachmentUrl", "Attachment")
End While

Windows.Forms.MessageBox.Show("All attachments uploaded successfully", "Attachments Upload", MessageBoxButtons.OK)

End Sub

How to check if there is any record in the data source for infopath rule

While develpoing InfoPath 2007 form there was a requirement to reset naming of forms at the change of year i.e. - eg. 12-01

Now we can do this by using couple of fields and get maximum no from data submitted document library. But issue is when we need to create a very first form into that published document library.

So while getting the maximum no we need to check if there is any record in document Library or not. If not then start by 1

Solution is to have a field in the document library to save the form no and get get max form no when new form loads and save into another field.

If max form no is blank then reset it from 1 else increment the no.

Tuesday, June 28, 2011

Changing the default language of existing Site collection or Web

While working on one Norwegion project I thought is there a way by which we could change the language of already created site collection so that we will not need to use Google translator to translate again and again.

After googling for few mins i found this article which says there is only one way to do so and its to run the sql update query


For changing the language of all sites in the content database to Dutch the query would be:
UPDATE dbo.Webs SET Language = 1043

Changing the language of one site collection can be done with:
UPDATE dbo.Webs SET Language = 1043 WHERE SiteId = [[SiteCollectionId]]

And for changing the language of a single web or subsite you can use:
UPDATE dbo.Webs SET Language = 1043 WHERE Id = [[WebId]]

Although it not a correct way to do so but while development if you want to see buttons text in english instead of other language which you cannot read then this is good alternative.

Just goto Central admin and find the content db of desired SC, get the id using manager and run the query.




Thursday, June 9, 2011

Generic method to get the SPListItem data from field internal lname or display name

Into one of the method of my code i had to display the list item data, but only those fields/columns that are set by Editor.

Now till that point i only knew that Editor will put column names in property bag as comma delimited but whether he will set internal name or display name of fields, no idea.

So I had to get the fields data by using some method which takes both Internal Name and Display name as parameter.

And here is the solution:

foreach (string field in fields)
details += Server.HtmlDecode(delimiter) +
Convert.ToString(item[item.Fields.GetField(field.Trim()).Id]);

Updated one entry of my custom resource file, but it does not get reflected in my web part

While working on one fix I faced on strange issue when I updated one entry of my custom resource file, but it did not get reflected in my web part.

I tried following but no effect:

* Deployed my solution
* Restarted IIS Manager
* Even gone to '14\Resources\MyFile.resx' and updated manually
* Deleted file from '14\Resources\MyFile.resx' and then deployed again
* Added new resource entry and updated my code

but with my last try I came to know that it is not picking resource data from '14\Resources folder' and instantly another location came into my mind and its

'C:\inetpub\wwwroot\wss\VirtualDirectories\9001\App_GlobalResources'
When i opened my resource file from this path.. it was old file....

So after updating here my issue got fixed, I cannot say its solution of all this kind of issues but it worked for me :)

Friday, May 20, 2011

Using JQuery to handle Add, Add All, Remove, Remove All, Up, Down process for two Select Box into Editor Part of custom Web Part

There was a requirement to develop a UI for Editor Part of my custom Web Part to add 2 select box and adding Add, Add All, Remove, Remove All functionality. Also i had to save selected images as webpart property and display into webpart on apply. UI is something like given image.

I added all UI from editor part class but for movements i used JQuery but when i try to save the data on Apply event i got an error:
Invalid postback or callback argument. Event validation is enabled using

After so much of googling and trying mutiple solutions i got in blogs finally i gone through this error by putting hidden text box and putting all selected image ids into it.

Here is code

As we had to create all controls at runtime into Editor Part Code also we had to send the ClientID for the controls which will be used by JQuery code added into js file so i added small script block to send ids to JQuery

Into CreateChildControls() of Editor Part

this.txtHiddenIDs = new TextBox();
this.txtHiddenIDs.ID = "hdnIDs";
this.txtHiddenIDs.Style.Add(HtmlTextWriterStyle.Visibility, "hidden");
this.txtHiddenIDs.Style.Add(HtmlTextWriterStyle.Position, "absolute");
this.Controls.Add(txtHiddenIDs);

if (!Page.ClientScript.IsClientScriptBlockRegistered("jscript"))
{
string jscript = "
<script type="text/javascript"><span style="font-size:85%;"> var $lstBoxAllItems = $('#" + lstBoxAllItems.ClientID + "'); var $lstBoxSelectedItems = $('#" + lstBoxSelectedItems.ClientID + "'); var $txtHiddenIDs = $('#" + txtHiddenIDs.ClientID + "'); ";
jscript += "
<script type="text/javascript" src="/_layouts/1033/EgSpi/Default/BannerEditorPart.js"></script>";
Page.ClientScript.RegisterStartupScript(typeof(string), "jscript", jscript, false);
}


Here is JQuery which do all Add/Add All/Remove/Remove All/Up/Down
$(document).ready(function () {
$lstBoxAllItems.val($('#' + $lstBoxAllItems.attr('id') + ' option:first').val())
});

$('#btnAdd').click(function () {
var options = $("#" + $lstBoxAllItems.attr('id') + ' option:selected');
options.each(function () {
$("#" + $txtHiddenIDs.attr('id') + '').val($("#" + $txtHiddenIDs.attr('id') + '').val() + ',' + $(this).val());
})

$('#' + $lstBoxAllItems.attr('id') + ' option:selected').appendTo($lstBoxSelectedItems);
$lstBoxAllItems.val($('#' + $lstBoxAllItems.attr('id') + ' option:first').val())
});

$('#btnRemove').click(function () {

var options = $("#" + $lstBoxSelectedItems.attr('id') + ' option:selected');
options.each(function () {
var idx = $("#" + $txtHiddenIDs.attr('id') + '').val().indexOf(',' + $(this).val())
$("#" + $txtHiddenIDs.attr('id') + '').val($("#" + $txtHiddenIDs.attr('id') + '').val().replace(',' + $(this).val(), ''));
})
$('#' + $lstBoxSelectedItems.attr('id') + ' option:selected').appendTo($lstBoxAllItems);
$lstBoxSelectedItems.val($('#' + $lstBoxSelectedItems.attr('id') + ' option:first').val());
});

$('#btnAddAll').click(function () {
var options = $("#" + $lstBoxAllItems.attr('id') + ' option');
options.each(function () {
$("#" + $txtHiddenIDs.attr('id') + '').val($("#" + $txtHiddenIDs.attr('id') + '').val() + ',' + $(this).val());
})

$('#' + $lstBoxAllItems.attr('id') + ' option').appendTo('#' + $lstBoxSelectedItems.attr('id') + '');
$lstBoxSelectedItems.val($('#' + $lstBoxSelectedItems.attr('id') + ' option:first').val());
});

$('#btnRemoveAll').click(function () {
$('#' + $lstBoxSelectedItems.attr('id') + ' option').appendTo('#' + $lstBoxAllItems.attr('id') + '');
$("#" + $txtHiddenIDs.attr('id') + '').val('');
$lstBoxAllItems.sort_select_box();
$lstBoxAllItems.sort_select_box();
$lstBoxAllItems.val($('#' + $lstBoxAllItems.attr('id') + ' option:first').val());
});

$('#btnMoveUp').click(function () {
$('#' + $lstBoxSelectedItems.attr('id') + ' option:selected').each(function () { $(this).insertBefore($(this).prev()) });

var options = $("#" + $lstBoxSelectedItems.attr('id') + ' option');
$("#" + $txtHiddenIDs.attr('id') + '').val('');
options.each(function () {
$("#" + $txtHiddenIDs.attr('id') + '').val($("#" + $txtHiddenIDs.attr('id') + '').val() + ',' + $(this).val());
})
});

$('#btnMoveDown').click(function () {
$('#' + $lstBoxSelectedItems.attr('id') + ' option:selected').each(function () { $(this).insertAfter($(this).next()) });

var options = $("#" + $lstBoxSelectedItems.attr('id') + ' option');
$("#" + $txtHiddenIDs.attr('id') + '').val('');
options.each(function () {
$("#" + $txtHiddenIDs.attr('id') + '').val($("#" + $txtHiddenIDs.attr('id') + '').val() + ',' + $(this).val());
})
});

$.fn.sort_select_box = function () {
$.fn.sort_select_box = function () {
var my_options = $("#" + this.attr('id') + ' option');
my_options.sort(function (a, b) {
if (a.text > b.text) return 1;
else if (a.text < b.text) return -1;
else return 0
})
$(this).empty().append(my_options);
$("#" + this.attr('id') + " option").attr('selected', false);
}
}

Monday, December 13, 2010

Opening a SharePoint Portal and Sending back form information to its parent Page

Last week I got another code challenge when I was given a task as follows:

  1. There will a be a popup which will open from Editor Part of my custom Web Part Properties
  2. User will select a user names from the list into popup and click Ok button.
  3. Now selected user names will be added into the list box control of Editor Part.

Solution:

As I had to bring the selected users from popup to parent page and parent List will be auto refreshed with the new added users.

So I kept my consolidated users details into one hidden textbox and do post back so that updated details gets refreshed in List box.

  1. Beacause we need to open SharePoint popup from Editor Part so we will have to write our popup opening javascript at runtime. As follows:
        private void GenerateJavascript()

{
string strPath = SPContext.Current.Web.Url + "/_layouts/Egspi/Default/DlgContactsSearch.aspx";
string strScript =
"function OpenDialog() { " +
"var options = SP.UI.$create_DialogOptions(); " +
"options.url = '" + strPath + "'; " +
"options.width = 360;" +
"options.height = 300; " +
"options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);" +
"SP.UI.ModalDialog.showModalDialog(options); " +
"}" +
"var messageId;" +

"function CloseCallback(result, target) { " +
"var strConsol='';" +
"if(result === SP.UI.DialogResult.OK) { " +
"var txtSearch = document.getElementById('" + txtContacts.ClientID + "');" +
"if (target != ''){" +
"var strExisting = txtSearch.value;" +
"var arrExisting = strExisting.split('#');" +
"var arrNew = target.split('#');" +
"var arrConsol = unique(arrExisting.concat(arrNew));" +
"strConsol = arrConsol.join('#');" +
"}" +
"txtSearch.value=strConsol; " +
"__doPostBack();" +
"}" +
"}" +

"function unique(arrayName) {" +
"var newArray = new Array();" +
"label: for (var i = 0; i < arrayName.length; i++) {" +
"for (var j = 0; j < newArray.length; j++) {" +
"if (newArray[j] == arrayName[i])" +
"continue label;" +
"}" +
"newArray[newArray.length] = arrayName[i];" +
"}" +
"return newArray;" +
"}" +

"function btnDeleteContacts_Click() {" +
"var strNewContacts = '';" +
"var txtSearch = document.getElementById('" + txtContacts.ClientID + "');" +
"var containerRef = document.getElementById('" + cblContacts.ClientID + "');" +
"var inputRefArray = containerRef.getElementsByTagName('input');" +
"var spanRefArray = containerRef.getElementsByTagName('span');" +
"for (var i = 0; i < inputRefArray.length; i++) {" +
"var inputRef = inputRefArray[i];" +
"if (inputRef.type.substr(0, 8) == 'checkbox') {" +
"if (inputRef.checked != true) {" +
"if (strNewContacts != '')" +
"strNewContacts += '#';" +
"strNewContacts += spanRefArray[i].getAttribute('optValue') + '~' + spanRefArray[i].getAttribute('optText');" +
"}" +
"}" +
"}" +
"txtSearch.value=strNewContacts;"+
"__doPostBack();" +
"}";

Page.ClientScript.RegisterClientScriptBlock(typeof(ContactsEditorPart), "ContactsDialogJavaScript", strScript, true);
}
 
  • OpenDialog(): This method will open our desired Popup.
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);

check out 2nd parameter it says that this method will be called from parent when popup will get closed.


  • CloseCallback(): This method will get the selected values into target parameter as string
    Then it will check any duplicate username which is already present into Editor Part List Control, if yes then it will remove it from the target string.
    Finally it will insert target string into my hidden text box.

  • Unique(): This is simple method to remove the duplicate array elements.

  • btnDeleteContacts_Click() : There is an option to select and delete any user from Editor Part list control.

Sunday, December 12, 2010

Opening a Sharepoint Portal and Sending back form information to its parent Page

Last week I got another code challenge when I was given a task as follows:

  1. There will a be a popup which will open from Editor Part of my custom Web Part Properties
  2. User will select a user names from the list into popup and click Ok button.
  3. Now selected user names will be added into the list box control of Editor Part.
Sol:

  1. Beacause we need to open SharePoint popup from Editor Part so we will have to write our popup opening javascript at runtime. As follows:

private void GenerateJavascript() { string strPath = SPContext.Current.Web.Url + "/_layouts/Egspi/Default/DlgContactsSearch.aspx"; string strScript = "function OpenDialog() { " +
"var options = SP.UI.$create_DialogOptions(); " + "options.url = '" + strPath + "'; " + "options.width = 360;" + "options.height = 300; " + "options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);" + "SP.UI.ModalDialog.showModalDialog(options); " + "}" + "var messageId;" + "function CloseCallback(result, target) { " + "var strConsol='';" + "if(result === SP.UI.DialogResult.OK) { " + "var txtSearch = document.getElementById('" + txtContacts.ClientID + "');" + "if (target != ''){" + "var strExisting = txtSearch.value;" + "var arrExisting = strExisting.split('#');" + "var arrNew = target.split('#');" + "var arrConsol = unique(arrExisting.concat(arrNew));" + "strConsol = arrConsol.join('#');" + "}" + "txtSearch.value=strConsol; " + "__doPostBack();" + "}" + "}" + "function unique(arrayName) {" + "var newArray = new Array();" + "label: for (var i = 0; i < arrayName.length; i++) {" + "for (var j = 0; j < newArray.length; j++) {" + "if (newArray[j] == arrayName[i])" + "continue label;" + "}" + "newArray[newArray.length] = arrayName[i];" + "}" + "return newArray;" + "}" + "function btnDeleteContacts_Click() {" + "var strNewContacts = '';" + "var txtSearch = document.getElementById('" + txtContacts.ClientID + "');" + "var containerRef = document.getElementById('" + cblContacts.ClientID + "');" + "var inputRefArray = containerRef.getElementsByTagName('input');" + "var spanRefArray = containerRef.getElementsByTagName('span');" + "for (var i = 0; i < inputRefArray.length; i++) {" + "var inputRef = inputRefArray[i];" + "if (inputRef.type.substr(0, 8) == 'checkbox') {" + "if (inputRef.checked != true) {" + "if (strNewContacts != '')" + "strNewContacts += '#';" + "strNewContacts += spanRefArray[i].getAttribute('optValue') + '~' + spanRefArray[i].getAttribute('optText');" + "}" + "}" + "}" + "txtSearch.value=strNewContacts;"+ "__doPostBack();" + "}"; Page.ClientScript.RegisterClientScriptBlock(typeof(ContactsEditorPart), "ContactsDialogJavaScript", strScript, true); }

  • OpenDialog(): This method will open our desired Popup.
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);

check out 2nd parameter it says that this method will be called from parent when popup will get closed.

  • CloseCallback: This method will get the selected values into target parameter as string

    Then it will check any duplicate username which is already present into Editor Part List Control, if yes then it will remove it from the target string.

    Finally it will insert target string into my hidden text box.

  • unique: This is simple method to remove the duplicate array elements.

  • btnDeleteContacts_Click() : There is an option to select and delete any user from Editor Part list control.


Monday, December 6, 2010

Security trimming on CustomActions tag for custom menu items and ribbon buttons

We often need to add a security trimming for our custom menu items or ribbon buttons using CustomActions tag.

Here is the solution

<customaction
ContentTypeId = "Text"
ControlAssembly = "Text"
ControlClass = "Text"
ControlSrc = "Text"
Description = "Text"
GroupId = "Text"
...
Rights = "Text"
..>

We can apply security trimming using 'Rights' attribute.

There are lot of options that can be used as value for this attribute.

Check out this link to see possible values


Happy Sharepointing :)

Monday, November 8, 2010

"BDC Metadata Store is currently unavailable" when I try to get the External Content Types on SPD

This issue I faced when I was trying to make one POC using BCS for SharePoint 2010.

First I found that my SP was trial so I upgraded it to "SharePoint Server with Enterprise Client Access License".

I was giving me same error even after upgrading then i saw on other vpc with same config and licence where it was working.

There I found the solution, which is that we need to do association of BDC service with the desired web application.

Goto : Central Admin -> Application Mgt -> Manage Web Application -> Select desired Web Application -> click 'Service Connections' from ribbon buttons -> in the popup make sure "Business Data Connectivity Service" is checked.

And bingo it worked..

Wednesday, October 20, 2010

Populate list items automatically when list definition feature gets activated

SharePoint 2010 - There was a requirement in which I had to populate 2 list items when its list definition feature gets activated.

Following is the solution:

Into Elements.xml file of list instance


< ?xml version="1.0" encoding="utf-8"?>

< Elements xmlns="http://schemas.microsoft.com/sharepoint/">

< ListInstance Title=....... ;">



< Data>

< Rows>

< Row>

< Field Name="Title">.....</Field>

< Field Name="MailBody">.....</Field>

< /Row>

< Row>

< Field Name="Title">.....</Field>

< Field Name="MailBody"></Field>

< /Row>

< /Rows>

< /Data>



< /ListInstance>

< /Elements>

Happy SharePointing.... :)

Validate CheckboxList Control with javascript to make sure atleast one checkbox is checked

While developing one page which sends mail to the selected group from the checkbox list I got requirement to impose validation to check atleast one group should be selected.

Here is the solution.....

< id="CvalGroupCheckbox" display="Dynamic" runat="server" cssclass="MsgLabel" errormessage="" clientvalidationfunction="validateGroupSelection">

< language="javascript" type="text/javascript">

function validateGroupSelection(source, arguments) {
document.getElementById("").style.visibility = "hidden";
var chkSubUsers = document.getElementById('_0');
var chkTestUsers = document.getElementById('_1');

if ((!chkSubUsers.checked) && (!chkTestUsers.checked))
arguments.IsValid = false;
else
arguments.IsValid = true;
}

< /script>

Happy programming.... :)

Monday, August 30, 2010

Query to SharePoint database and WSS_Logging Database

While googling for my What's Hot web part I found 2 very good articles which explains why we should not query sharepoint db. And how we can use WSS_Logging db


Cheers

Monday, August 23, 2010

Monitoring SharePoint Usage through an ASP.NET Web Application

Monitoring SharePoint Usage through an ASP.NET Web Application
By Gayan Peiris

This is very good article for creating an application which can show a desired site usage details


Thursday, August 19, 2010

How to get a month name from date

We can get the month name using following statement

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(datValue.Month)

Cheers..

How to get all available page layouts which can be used to create and page

There was a task in which i had to check what all page layouts are available for a current site which can be used to create a new page. So here is the solution

PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

PageLayout[] pageLayouts = pubWeb.GetAvailablePageLayouts();

PageLayout pageLayout = pageLayouts.Where(p => p.Title.Trim() == item["LayoutName"].ToString().Trim()).FirstOrDefault();

if (pageLayout == null)
.......

Cheers....

Check if List or document/Picture library already exists

During one of my project i came accross this situation many time when i had to check whether list or document library already exists or not. So here is the solution


To check document/picture library there is an existing method which can be used like below

if (!web.GetFolder(strName).Exists)
{
......
}

Here 'strName' is the name of document/picture library.

But for list this method does not work. Unfortunately there is no method to check if list exists so we need to do a trick for that, check out below

SPList list = null;
try
{
list = web.Lists[strListTitle];
}
catch { }
if (list == null)
{
.....

Cheers.





Sunday, August 1, 2010

Check if Page is already checked out

It is very helpful while editing the contents of a publishing page to check if desired page is already checked or not.

Here is is the code to check this

Sol 1:

if (pPage.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
pPage.CheckOut();

Sol 2:

SPFile fileSource = web.GetFile(strSourceFilePath);
SPUser user = null;
user = fileSource.CheckedOutBy;

if (user != null)
{....


If we does not check so then we may get error that page is already checked out.

Open a SharePoint popup after server trip

Last day i had a task in which when user clicks a button few pages got created at runtime and after this i had to show the popup window which will show a aspx page having status of all created pages whether successfully created or failed.

Challenge was to open the popup when button click server trip done (Page rerendered).

My method was creating a javascript at run time to open a popup. But issue was when it runs i gets a javascript error.

"Object Doesn't support this property or method"

Issue was my javascript was getting called even before its supporting js files gets load.

After some rnd i found the solution and here it is.

string strScript = "function OpenDialog() { var option = SP.UI.$create_DialogOptions(); option.url = '" + strPath + "'; option.width = 380; option.height = 330; SP.UI.ModalDialog.showModalDialog(option); } ExecuteOrDelayUntilScriptLoaded(OpenDialog, \"sp.ui.dialog.js\");";

ClientScript.RegisterClientScriptBlock(this.GetType(), "ShowStatusfunction", strScript, true);


Key thing is ExecuteOrDelayUntilScriptLoaded(OpenDialog, \"sp.ui.dialog.js\");";

What it does is, it will wait untill the specified js gets load then it will call the method

Cheers...