2009/12/30

Problem of postBack in sharepoint

while dealing with Response.End() I found that the postback events are disabled. I posted to MSDN Forum and thy responded on my post by the following:

Try to add this code to onClienClick event of the button to enable sharepoint post back event as the following

ButtonName.OnClientClick = "_spFormOnSubmitCalled = false;_spSuppressFormOnSubmitWrapper=true;";

my post on the following URL

2009/12/29

Creating Custom properties in WebPart

For adding custom properties in webparts you can follow this article it is very useful.
http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx

2009/11/04

Export dataGrid to excel

if you need to export dataGrid to excel sheet you can do it as the following.
1- get dataGrid object with data.
2- create object of HtmlTextWriter.
3- try to write the Grid using HtmlTextWriter in you response.

as the following in button_Click event of any other location you want to perform this action.

string attachment = "attachment; filename=RegisteredUsers.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "UTF-8";
Response.ContentType = "application/vnd.ms-excel";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
GridView grd = new GridView();
grd.DataSource = EntityDataSource1;
grd.DataBind();

grd.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();

Changing machine name Problem in sharepoint

When I tried to change the machine name while I already have sharepoint server installed on this machine with many publishing webApplications, the problem is central administration and sharepoint websites can't load.
So, you can do it as the following.

1- change the machine name from computer settings to the name you want.
2- open RUN
3- goto the destination of stsadm (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN)
4- Now you can run the following command line
stsadm -o renameserver -oldservername -newservername .

5- The last step is to open centeral administration and change the servername from the URL to (localhost). goto to Operation Tab, choose alternative mapping access and change the machine name at all mapping URLs to your new one.

2009/09/24

CAML Query that filters on the current user


CAML Queries are troublesome at the best of times. I find it best to use a tool or a tried and tested method like the one I use here Tip - Creating CAML Queries - Thinking out aloud - Dave Hunter's.

When you create a view and you want to show only items that have been created by the current user you use the [Me] keyword.
For example: filter by "Author" equals [Me].

How can I do this using a CAML query?

The [Me] keyword is represented in CAML by the following <Value Type="Integer"><UserID Type="Integer"/></Value>.

In the CAML query for returning items that the current user has created becomes ...

<Where><Eq><FieldRef Name='Author' /><Value Type="Integer"><UserID Type="Integer"/></Value></Eq></Where>

Mirjam has done a good job of writing this up http://www.sharepointblogs.com/mirjam/archive/2009/07/16/creating-a-custom-view-that-filters-on-the-current-user-or-me.aspx. Glad I could help.

2009/08/18

SharePoint - using the rich text box in a custom user control

Frustration aplenty with this one. Logic dictated that the RichTextField control in SharePoint would have been the one to use...
but no, it's not (as i found out)...so how do you use that shiny nice Rich Text Box control in a custom web part or user control.


simple - so simple i'm sad to say it took me 1 1/2hrs discussing it with some like-minded fellows before we found out what it was (sad i know, but we got there in the end).
Add this to your ascx (if you're using a web user control):

1: <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

and here comes the simple bit..

1:


That's it...not that impressive but that's what you have to do..simple eh :)
Note: this is only available in MOSS 2007.

The article is published by http://msmvps.com/blogs/brianmadsen/archive/2008/03/14/sharepoint-using-the-rich-text-box-in-a-custom-user-control.aspx

2009/08/11

OutOfMemory Exception

I am using customList to add some requests from Anonymouse useres.

But when I used EventHandler it gives me exception "OutOfMemory exception" while my code was as the following:

SPSecurity.RunWithElevatedPrivileges(delegate()
{

SPWeb web = SPControl.GetContextWeb(Context);
web.AllowUnsafeUpdates =true;

SPListItem item = web.Lists["MyList"].Items.Add();
item["RequestedName"] = textBoxName.Text;
item["DateRequestRecievd"] = DateTime.Now;
item["RequestedPhoneNo"] = textBoxMobileNo.Text;
item["RequestType"] = dropDownListRequestType.SelectedItem.Value;
item["RequestSubject"] = textBoxRequestSubject.Text;
item["state"] = textBoxState.Text;
item["IdentityNo"] = textBoxIdentityNo.Text;
item.Update();
web.AllowUnsafeUpdates =false;
});

I used that code because I know that "SPSecurity.RunWithElevatedPrivileges" imporsenates the current user permissions with "system Account" Permissions. But it doesn't work with Anonymouse users.


There the solution of this Issue Anonymouse doesn't have permission to access assembly. So, you need to Authonticate as an authonticated user. I created a user that will be used for imporsenation, "Domain\Visitors". I wrote the following code
1 SPSecurity.RunWithElevatedPrivileges(delegate()
2 {
3 using (SPSite site = new SPSite(SPContext.Current.Site.Url))
4 {
5
6 using (SPWeb parentWeb = site.OpenWeb())
7 {
8 string userName = ConfigurationManager.AppSettings["contactUsUser"];
9 SPUser user = parentWeb.AllUsers[userName];
10 ////YOU CAN ALSO HARD CODE THE USER AS BELOW
11 //SPUser user = parentWeb.AllUsers["DOMAIN\\Vistors"];
12 SPUserToken token = user.UserToken;
13
14 using (SPSite s = new SPSite(SPContext.Current.Site.Url, token))
15 {
16 using (SPWeb web = s.RootWeb)
17 {
18 //MY LOGIC HERE
19 }
20 }
21
22 }
23
24 }
25 });

you can see my post on MSDN Forum

2009/06/23

Using Javascript to access a List Form Field in SharePoint Designer


An article was posted showing how to access and manipulate a List Form Field within SharePoint Designer using Javascript over at Microsoft SharePoint Designer Team Blog. The code in the article supported the following types of SharePoint 2007 form fields, but not the Radio Buttons Choice field:



Single Line of Text
Multiple Lines of Text
Number
Currency
Choice (dropdown)
Lookup (single)
Lookup (multiple)
Yes/No
So I’ve modified the function getTagFromIdentifierAndTitle and added onto it the code to allow accessing Radio Buttons Choice fields. The following is the modified function:
/*******
SharePoint Field Type identifier tagName Option
--------------------- -------------- --------- ---------
Single Line of Text TextField input
Multiple Lines of Text TextArea input
Number TextField input
Currency TextField input
Choice (radio buttons) RadioButtons input
Choice (radio buttons) RadioButtons input value
Choice (dropdown) DropDownChoice select
Lookup (single)* Lookup select
Lookup (multiple) SelectCandidate;
SelectResult select
Yes/No BooleanField input
******/
function getTagFromIdentifierAndTitle(tagName, identifier, title, option) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var idString = tags[i].id;
var nameString = tags[i].name;
// get selected radio button value only
if (option == "value" && tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
if (tagParentHTML.indexOf('FieldName="'+title+'"') > -1) {
var radioButtons = document.getElementsByName(nameString);
var radioValue = "";
for (var x=0; x < radioButtons.length; x++) {
if (radioButtons[x].checked) {
radioValue = radioButtons[x].parentElement.title;
break;
}
}
var o = document.createElement("INPUT");
o.type = "hidden";
o.value = radioValue;
return o;
}
}
// get radio buttons group
if (tags[i].type == "radio" && (identifier == "RadioButtons" && nameString.indexOf(identifier) == nameString.length - len)) {
var tagParentHTML = tags[i].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.innerHTML;
if (tagParentHTML.indexOf('FieldName="'+title+'"') > -1) {
return document.getElementsByName(nameString);
}
}
// all other input or select type
else if (tags[i].title == title && (identifier == "" idString.indexOf(identifier) == idString.length - len)) {
return tags[i];
}
}
return null;
}



Here is how you would use the function above for Radio Buttons:
// to get the selected radio button and its value
var myRadioButtonsSelected = getTagFromIdentifierAndTitle("input","RadioButtons","MyFieldName","value");
var myRadioButtonsValue = myRadioButtonsSelected.value;

// to get the array for radio buttons
var myRadioButtonsArray = getTagFromIdentifierAndTitle("input","RadioButtons","MyFieldName");
for (var x=0; x < myRadioButtonsArray.length; x++) {
// do whatever you like here...
// for example:
myRadioButtonsArray[x].parentElement.onclick = function(){alert(myRadioButtonsArray[x].value);};
}


The original post can be found here: Using Javascript to Manipulate a List Form Field
For a basic function, you could also check out Boris Gomiunik’s Blog for another post about referencing SharePoint form fields using Javascript.

compare dates in sharepoint using JavaScript

you can use the current code to check the differance between dates before saving data using JavaScript code.

The following code I used to use it in case of check dates I hope it will be useful.

function PreSaveAction()

{

var date1 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Letter Date");

var date2 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Decision Date");

var date3 = getTagFromIdentifierAndTitle("INPUT","DateTimeFieldDate","Request Date");

var arrDate1 = date1.value.split("/");

var useDate1 = new Date(arrDate1[2], arrDate1[1]-1, arrDate1[0]);

var arrDate2 = date2.value.split("/");

var useDate2 = new Date(arrDate2[2], arrDate2[1]-1, arrDate2[0]);

var arrDate3 = date3.value.split("/");

var useDate3 = new Date(arrDate3[2], arrDate3[1]-1, arrDate3[0]);

if(useDate1 >= useDate2)

{

alert("Letter date must be before Decision Date");

return false; // Cancel the item save process

}

else if(useDate2 >= useDate3)

{

alert("Decision Date must be before Request Date");

return false; // Cancel the item save process

}

else

{

return true; // OK to proceed with the save item

}

}

//getTagFromIdentifierAndTitle function

function getTagFromIdentifierAndTitle(tagName, identifier, title)

{

var len = identifier.length;

var tags = document.getElementsByTagName(tagName);


for (var i=0; i < tags.length; i++ )
{

var tempString = tags[i].id;

if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))

{

return tags[i];

}

}

return null;

}


2009/06/22

To disable right click on webpage

you can disable the right click on webpage using the following javascript code:

<script language="JavaScript1.1">

<!-- Begin function right(e)

{

if (navigator.appName == 'Netscape' && (e.which == 3 e.which == 2))

return false;

else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 event.button == 3))

{

alert(" ");

return false;

}

return true;

}

document.onmousedown=right;

document.onmouseup=right;

if (document.layers) window.captureEvents(Event.MOUSEDOWN);

if (document.layers) window.captureEvents(Event.MOUSEUP);

window.onmousedown=right;

window.onmouseup=right;


// End -->
</script>

2009/06/03

WPSC undefined JavaScript error.


While using Forms Authontication I met the following JS error "WPSC" object isnot defiend, and I added the following code then this error disappeared.


<script type="text/javascript">


if(typeof(WPSC) == "undefined"){


WPSC = new Object();


WPSC.Init = function(){


//do nothing
}


WPSC.WebPartPage = new Object();


WPSC.WebPartPage.Parts = new Object();


WPSC.WebPartPage.Parts.Register = function()


{
//do nothing
}


}


</script>

2009/05/17

Printing WebPage using JavaScript


for printing a webpage using javascript you can use the following code it is very usefull for printing any HTML content.


you can change elem with the content you want to print.


function PrintPage()


{


var elem= myBody();


var popup = window.open(' ','popup','toolbar=no,menubar=no,width=200,height=300');


popup.document.open();


popup.document.write("<html><head><meta name="'WebPartPageExpansion'" content="'full'"></head><body onload="'print()'">");


popup.document.write(elem); popup.document.write("</body></html>");


popup.document.close();


}

2009/04/27

CAML query with Person or People and Groups column in Sharepoint 2007 (using in Event Handlers)


I was facing an issue with my simple CAML query where I was trying to filter the Field inside Sharepoint List and supplying value from the properties.AfterProperties of List Item event handler. This field was of Person or to say People and Groups kind of field. Internally inside sharepoint this value is stored as USERID and not as the display name. So I was using a simple CAML builder to build my query and it looked like:

oQuery.Query = "<Where><And><Eq><FieldRef Name='Team_x0020_Member' />" +
"<Value Type='User'>" + properties.Afterproperties[“Team_x0020_Member”].ToString() + "</Value>" + "</Eq>" +
"<Eq><FieldRef Name='Year' /> <Value Type='Choice'>" + properties.AfterProperties["Year"].ToString() +
"</Value> </Eq></And></Where>";


And this never worked for me, then one of my colleagues Madhur Ahuja helped me crack this it was a simple Lookup attribute that was missing, so basically the query should have been:

oQuery.Query = "<Where><And><Eq><FieldRef Name='Team_x0020_Member' LookupId= 'TRUE' />" +

"<Value Type='User'>" + properties.Afterproperties[“Team_x0020_Member”].ToString() + "</Value>" +
"</Eq>" +

"<Eq><FieldRef Name='Year' /> <Value Type='Choice'>" +
properties.AfterProperties["Year"].ToString() +

"</Value> </Eq></And></Where>";


And this never worked for me, so bottom line if you use People and Groups kind of column in Filters always make sure that you use LookupId ='TRUE' attribute in Filters

2009/04/15

SharePoint Security Access Check Codeplex


A colleague of mine just pointed me to this interesting tool ...

http://www.codeplex.com/AccessChecker

Quickly check what objects within a Sharepoint site hierarchy a user has access to. The Access Checker Web Part is a Windows Sharepoint Services Web Part, for use within Windows Sharepoint Services v3 and Microsoft Office Sharepoint Server 2007, that displays a tree view showing permissions on objects for a user scoped to a Site hierarchy. It also has a second mode which will show the permission inheritance of objects within a Site hierarchy.

2009/03/20

How to Uninstall Microsoft SQL Server 2005 Embedded Edition (SSEE Instance)


you need to uninstall Microsoft SQL Server 2005 Embedded Edition (SSEE Instance) while uninstalling windows sharepoint services.

Simply execute the following command in a windows console :
(on 32-bit platforms)
msiexec /x {CEB5780F-1A70-44A9-850F-DE6C4F6AA8FB} callerid=ocsetup.exe

(on 64-bit platforms)
msiexec /x {BDD79957-5801-4A2D-B09E-852E7FA64D01} callerid=ocsetup.exe

2009/03/10

Add previlages to user to do some actions in WSS 3.0 / MOSS 2007


We can use this method for dealing with users that has low previlages over specific List.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPListItem NewUser = NewUsersList.Items.Add();
NewUser["Username"] = _userNameTextBox.Text.Trim();
NewUser["Password"] = _passwordTextBox.Text.Trim();
NewUser["First Name"] = _firstNameTextBox.Text.Trim();
NewUser["Last Name"] = _lastNameTextBox.Text.Trim();
NewUser["Phone"] = _phoneTextBox.Text.Trim();
Site.AllowUnsafeUpdates = true;
NewUser.Update();
}
);

WSS 3.0 Allow Unsafe Updates


you can use the following property in custom WebPart:

Web.AllowUnsafeUpdates = true;

{ Your Code here }

Web.AllowUnsafeUpdates = false;

this property can be used with anonymous or user with low permissions.

2009/03/03

Map of Reusable SharePoint JavaScript

JSRequest



version: WSS 3.0
source file: init.js (ln 1621)
mapped by: Itay Shakury
purpose: provides method to parse query string, filename, and pathname from URL
example:



JSRequest.EnsureSetup();
var qs = JSRequest.QueryString[value];
var fn = JSRequest.FileName;
var pt = JSRequest.PathName;


PreSaveAction()



version: WSS 3.0
source file: n/a (ref: form.js ln 5909)
mapped by: Edin Kapic
purpose: provides hook for creating custom function interrupting submit action
example:



function PreSaveAction(){
var input = getTagFromIdentifierAndTitle("textarea","","Test");
if(input && input.value == "") {
alert("You must complete Test");
return false; // Cancel the item save process
}
return true; // OK to proceed with the save item
}


_spBodyOnLoadFunctionNames



version: WSS 3.0
source file: n/a
mapped by: Sanjay Arora
purpose: Allows you to register additional JavaScript methods that should run in the PageLoad event
example:


_spBodyOnLoadFunctionNames.Push('MyCustomFunctionName');


GetFirstChildElement(e)



version: WSS 3.0
source file: core.js
mapped by: Christophe
purpose: get the first "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.


GetLastChildElement(e)



version: WSS 3.0
source file: core.js
mapped by: Christophe
purpose: get the last "real" child of a DOM element. This function is useful for Firefox, which interprets a line break as a child element.


GetCBSelectedValues(frm)



version: WSS 3.0
source file: core.js (ln 972)
mapped by: Paul Grenier
purpose: Accepts a form object, loops through all check box elements and returns the values of the checked boxes or false if none are checked.
example:
html


<input id="spUserSelCb_1131" type="checkbox" title="Paul Grenier" onclick="UserSelectionOnClick(this,'1');" value="131" name="spUserSelectionCheckBox_1"/>


JavaScript



var elm = document.getElementsByTagName("form")[0];
GetCBSelectedValues(elm)

Object returned: strList = "131,144,143,7,254,22..."


GetSelectedValue (frmElem)



version: WSS 3.0
source file: init.js (ln 1516)
mapped by: Paul Grenier
purpose: takes a form element with a selectedIndex and returns the selected value or an empty string.


GetSelectedText(frmElem)



version: WSS 3.0
source file: init.js (ln 1523)
mapped by: Paul Grenier
purpose: takes a form element with a selectedIndex and returns the selected text or an empty string.


escapeProperly(str)



version: WSS 3.0
source file: init.js (ln 168)
mapped by: Paul Grenier
purpose: takes any string and returns a URL-encoded string.
example:
escapeProperly("this is a test")


"this%20is%20a%20test"


unescapeProperly(str)



version: WSS 3.0
source file: init.js (ln 855)
mapped by: Paul Grenier
purpose: takes any URL-encoded string and returns a string.
example:
unescapeProperly("this%20is%20a%20test")


"this is a test"



refrance : http://sharepointdevwiki.com/display/public/SharePoint+JavaScript+Functions+Overview

2009/03/02

Hide fields in NewForm.aspx without customization


You can use the following techniqe to hide flags that you add in custom list or document library without customization you can add the following code after the ContentPlaceHolder tage


<asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”>


The script as the following:


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

// set the function that will load in the page call.


_spBodyOnLoadFunctionNames.push("hideFields");


//the function that will search for control


function findacontrol(FieldName) {

var arr = document.getElementsByTagName("!");
// get all comments
for (var i=0;i < arr.length; i++ )
{
// now match the field name
if (arr[i].innerHTML.indexOf(FieldName) > 0)
{ return arr[i]; }
}
}



// this function wil hide the controls by field Name



function hideFields()
{
var control = findacontrol("Hired");
control.parentNode.parentNode.style.display="none";
control = findacontrol("inServe");
control.parentNode.parentNode.style.display="none";
control = findacontrol("Title");
control.parentNode.parentNode.style.display="none";
}


</script>


you can change the Green text with your controls name that you need to hide

2009/02/22

TextBox accepts only numbers


<asp:TextBox " runat="server" id="txt1" onkeypress="return isNumberKey(event)" />

This is the javascript method that will be called by the textbox on onkeyPress event
<SCRIPT type="text/javascript" language=Javascript>

<!--
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
//-->
</SCRIPT>

2009/02/14

Get SelectedValue from sharepoint lookup Field


<SharePoint:FormField runat="server" id="ff30{$Pos}" ControlMode="New" FieldName="_x0627__x0644__x0628__x0646__x06" __designer:bind="{ddwrt:DataBind('i',concat('ff30',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@_x0627__x0644__x0628__x0646__x06')}" />

<SharePoint:FieldDescription runat="server" id="ff30description{$Pos}" FieldName="_x0627__x0644__x0628__x0646__x06" ControlMode="New"/>

To get the selectedvalue from sharepoint lookup field you follow these steps.

first you need to assign event onchange to this field.


<script type="text/javascript" language="javascript">
//Select the method that will run at the sharepoint page body load

_spBodyOnLoadFunctionNames.push('setEvent');

//set event function
function setEvent()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');

//eventName and method that will call
selectBank.setAttribute('onchange',checkBank);


}

//function will call when event is fired
function checkBank()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');
var selectedValue=selectBank.options[selectBank.selectedIndex].value;
alert(selectedValue)

}

</script>


Get SelectedValue Of dropdownlist


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

var s1= document.getElementById('Select1');

var selectedValue=s1.options[s1.selectedIndex].value;

alert('selectedValue');


</script >

2009/02/08

Linking Sql Server 2005 to Oracle


This is copied article but I think it is usefull.

Oracle-SS2005 Linked ServersHere is a quick guide to setting up linked servers so you can query Oracle through Sql Server.

For my testing of this I used Sql Server Express 2005, and Oracle 9.2. This all uses simple commands that can be run via Query Analyzer or Query Tool.
First, if you've been doing this and having issues, you need to clear out any of your linked server's logins:
sp_droplinkedsrvlogin
@rmtsrvname = 'LINKED_ORA',
@locallogin = nullNext,
drop the server

EXEC sp_dropserver LINKED_ORAOk,

now let's add the linked server to Sql Server.
The linked server will be called LINKED_ORA. Once this is done you should see this listed in SS Management Studio under Server Objects->Linked Servers-- add server
EXEC sp_addlinkedserver
@server= 'LINKED_ORA',
@provider='MSDASQL',
@srvproduct='Oracle',
@datasrc= 'myOracle'
@server - this is the name to use.
It can be anything
@provider - can be either MSDASQL and MSDAORA.
Both seem to both work fine. There is talk of another provider from Oracle, but I have not gotten this one to work.
@srvproduct - must be "Oracle". I do not know why this matters
@datasrc - this is a DSN that you have set up using Oracle's .NET managerNow,
the Oracle system does not implicitly let Sql Server connect.

You need to add a login for this linked server to use.

-- add login - the DSN is protected by a password
EXEC sp_addlinkedsrvlogin
@rmtsrvname='LINKED_ORA',
@useself='false',
@rmtuser='oracleUserId',
@rmtpassword='oraclePassword'

Once this is set, then you can test using this command:
--verify tables OK
exec sp_tables_ex
@table_server = 'LINKED_ORA',
@table_schema='MySchema'
@table_schema is optional. If not provided, you will get a list of all tables in all schemas.

This will return information about the tables in the linked server.

I use it as a basic diagnostic to verify that the linked server is working. if it's not, then I use the scripts above to delete the login and linked server, then re-create using other inputs.

Now, the big pain with Oracle is that you cannot just query into the database.

I know, it is ridiculous, but I found that only OPENQUERY works.
Here is how it looks:

SELECT * FROM OPENQUERY( LINKED_ORA, 'SELECT * FROM Exp.Proj')

But from there you can now do handy things in Sql Server. One of my favorites is to re-create the Oracle schema in a Sql Server database, then use INSERT to pull in all of the Oracle data. Then you can just work with Sql Server!

Getting Vlaue of UserField In Sharepoint using JavaScript


If you need to get the value of userFiled control using javascript.

<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="_x0627__x0644__x0631__x0642__x06" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@_x0627__x0644__x0631__x0642__x06')}"/>



<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="_x0627__x0644__x0631__x0642__x06" ControlMode="New"/>



you can search for this ID in viewsource you can find many controls one of these controls is Span it's ID will be in my case



"ctl00_m_g_271a3a52_3741_466d_80b4_eb05da86cc05_ff2_1_ctl00_ctl00_UserField"



you can use the following code to preview the value of the control



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

function CheckUser()

{

var selectedUser= document.getElementById('ctl00_m_g_271a3a52_3741_466d_80b4_eb05da86cc05_ff2_1_ctl00_ctl00_UserField').innerText; alert(selectedUser); return false;

}

</script>




This control contains the value of this field

It will breview the following value
then you can use this value in filteration or any other Issue





2009/02/07

SharePoint Built-in JS Functions


//Get Current User ID
_spUserIdex:
alert(_spUserId);

//Run JS Function on Page Load
_spBodyOnLoadFunctionNames.push(' FunctionName ');

//First we must call the EnsureSetup method
JSRequest.EnsureSetup();

//Get a query string parameter called ItemId. i.e - "page.aspx?ItemId=11" will return 11
itemId = JSRequest.QueryString["ItemId"];

//Get the current page name. i.e - "default.aspx"
itemId = JSRequest.FileName;

//Get the current path name. i.e - "/doclib/default.aspx"
itemId = JSRequest.PathName;

2009/02/02

Change SharePoint Page Title


Add the follwing content place holder in the top of your code if not exist
< asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">

<?xml:namespace prefix = asp /><asp:content contentplaceholderid="PlaceHolderPageTitle" runat="server">Add Title here</asp:content>

</asp:Content >

You can get title dynamic by adding any of this tags into "PlaceHolderPageTitle"

<sharepoint:listproperty runat="server" property="Title">
< SharePoint:ListProperty Property="Title" runat="server"/> <sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
<sharepoint:listitemproperty runat="server" property="Title">
<SharePoint:ListItemProperty Property="Title" runat="server"/>
<SharePoint:ProjectProperty Property="Title" runat="server"/>
<SharePoint:ListFormPageTitle runat="server"/>

<sharepoint:projectproperty runat="server" property="Title">

<sharepoint:listformpagetitle runat="server">


</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listproperty>
<?xml:namespace prefix = sharepoint />
<sharepoint:listproperty runat="server" property="Title">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listproperty>
<sharepoint:listproperty runat="server" property="Title">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
</sharepoint:listformpagetitle></sharepoint:projectproperty></sharepoint:listitemproperty>
</sharepoint:listproperty><sharepoint:listproperty runat="server" property="Title">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
</sharepoint:listformpagetitle></sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listproperty></sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>

2009/01/28

Oracle connection string for C#


using System;using System.Data;
using System.Data.OleDb;

class OleDbConnectionOracle
{
public static void Main()
{
string connectionString = "provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER";

OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
myOleDbCommand.CommandText = "SELECT empno, ename, sal FROM emp WHERE empno = 7369";

myOleDbConnection.Open();
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
myOleDbDataReader.Read();
Console.WriteLine("myOleDbDataReader[\" empno\"] = " + myOleDbDataReader["empno"]);
Console.WriteLine("myOleDbDataReader[\" ename\"] = " + myOleDbDataReader["ename"]);
Console.WriteLine("myOleDbDataReader[\" sal\"] = " + myOleDbDataReader["sal"]);
myOleDbDataReader.Close();
myOleDbConnection.Close();
}
}