Monday, October 27, 2008

Download Data File From SharePoint

How to download Files From SharePoint Using php?

This example is useful to download sharepoint data file using php. I have try to download sharepoint file using PHP CURL and i have done it so try it.

<?php
$sp_login_id = "test"; // sharepoint user id
$sp_password = "********"; //sharepoint password
$sp_data_file_url = "http://server/test.doc"; // data file url


$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$sp_data_file_url); // set url to post to
curl_setopt($ch, CURLOPT_USERPWD,"$sp_login_id:$sp_password");
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // curl error
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 5000); // times out after 5s
curl_setopt($ch, CURLOPT_GET, 1); // set GET method
$result = curl_exec($ch); // execute the whole process

//curl errors
$curl_info = curl_getinfo($ch);
switch($curl_info["http_code"]){
case 401:
die("Incorect userid or password.");
break;

case 404:
die("Incorect data file URL.");
break;
}

$fo@fopen(basename($sp_data_file_url),"w");
@fwrite($fo,$result);
@fclose($fo);
?>

Wednesday, October 22, 2008

JavaScript Cookies Functions

Java Script Cookies Set and Get functions

There are four function which is useful to work with javascript cookies. there are no predefine function in javascript so that we can use these function to work with browser cookies. here is description of functions.

1) Javascript function set_cookie(name,value) :- This is a void function take two parametters name & value. name param is used for cookies name & value is used to set cookies value.

2) Javascript function get_cookie(name) :- This string function, which return value of that particualr cookie which you pass as param.

3) Javascript function is_cookie(name) :- This is boolean function, which return true or false for cookies existence.

4) javascript function delete_cookie(name) :- This is a void function which is used to delete cookies. name param takes name of cookies which you want to delete.


<Script Language="javascript">

function set_cookie(name,value){
var name=name.toLowerCase();
document.cookie=name+"="+value;
}

function is_cookie(name){
var name=name.toLowerCase();
var str=document.cookie.indexOf(name+"=");
if(str>=0){
return true;
}else{
return false;
}
}

function get_cookie(name){
var name=name.toLowerCase();
var str="";
if(is_cookie(name))
{
var cStr=document.cookie.split(";");
for(var i=0;iif(cStr[i].indexOf(name)>=0){
str=cStr[i].substring(cStr[i].indexOf("=")+1,cStr[i].length);
}
}
}else{
str="";
}
return str;
}

function delete_cookie(name){
var name=name.toLowerCase();
set_cookie(name,'');
}
set_cookie("color","green");
document.bgColor=get_cookie("color");

</Script>

Wednesday, October 15, 2008

Dynamic Array Collection Using Flex

We can create dynamic Array Collection in flex using following code.

var ob:Object;
var n:String = "Name";
var a:String = "Address";
var ar:ArrayCollection = "";

ob = new Object();

ob[n] = "Ar";
ob[a] = "xyz, UK";

ar = new ArrayCollection();
ar.addItem(ob);


It binds data into array just like.

arrayCollection = [{Name:'Ar',Address:'xyz, UK'}];

setPropertyIsEnumerable() is use to hide ArrayCollection item. which we can use like.


ar.setPropertyIsEnumerable("Name",true);


After using above method we can hide array collection item.

Tuesday, October 14, 2008

Javascript Trim Function Problem

There is no function to trim string in javascript. We can use following user define function to trim string using javascript. Mainly we need three type of trim function which we use in program.

Right Trim Javascript User Define function.

function rightTrim(str)
{
return str.replace(/\str+$/,"");
}

Left Trim Javascript User Define function.

function leftTrim(str)
{
return str.replace(/^\str+/,"");
}

Trim javascript function for both left and right side.

function trim(str)
{
return str.replace(/^\str+|\str+$/g,"");
}

Wednesday, September 17, 2008

Flex Cache Problem

There is very big problem in flex that's cache problem. When I was developing a Rich Internet application. I faced flex cache problem in Internet Explore & Firefox browser i was stuck badly.

Then I wrote this code for avoiding flex cache problem & i think it works a bit. Well still working on it.

I have added this code into index.template.html which is located into flex project html-template/index.template.html.

<Script Language="javascript">
var url = location.href;
var ots = parseInt(url.substring(url.indexOf("=")+1,url.length))+6000;
var dt = new Date();
var n = dt.getTime();
if(url.indexOf("?timeStamp=")!=-1)
{
if(isNumber(ots) && ots!=""){
if(nts>ots){
location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+nts;
}
}else{
location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+newTimeStamp;
}
}else{

location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+nts;
}

function isNumeric(val)
{
var vc = "0123456789.";
var isnum=true;
var c;
for (i = 0; i < val.length && isnum == true; i++)
{
c = val.charAt(i);
if (vc.indexOf(c) == -1)
{
isnum = false;
}
}
return isnum;
}
</Script>


Changes which i made in swf javascript code.


<script language="JavaScript" type="text/javascript">
<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if ( hasProductInstall && !hasRequestedVersion ) {
// DO NOT MODIFY THE FOLLOWING FOUR LINES
// Location visited after installation is complete if installation is required
var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
var MMredirectURL = window.location;
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
var MMdoctitle = document.title;

AC_FL_RunContent(
"src", "playerProductInstall",
"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
"width", "${width}",
"height", "${height}",
"align", "middle",
"id", "${application}",
"quality", "high",
"bgcolor", "${bgcolor}",
"name", "${application}",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else if (hasRequestedVersion) {
// if we've detected an acceptable version
// embed the Flash Content SWF when all tests are passed
AC_FL_RunContent(
"src", "${swf}"+"?run="+newTimeStamp,
"width", "${width}",
"height", "${height}",
"align", "middle",
"id", "${application}",
"quality", "high",
"bgcolor", "${bgcolor}",
"name", "${application}",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else { // flash is too old or we can't detect the plugin
var alternateContent = 'Alternate HTML content should be placed here. '
+ 'This content requires the Adobe Flash Player. '
+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
document.write(alternateContent); // insert non-flash content
}
// -->
</script>


Httpservice not refreshing there's another point of flex cache. Some time Httpservice does not show refresh result in second time so we just use a parameter which we can send into with Httpservice Request.

Flex Function
public static function uniqueNum():String{
var d:String = new Date().getDate().toString();
var m:String = new Date().getMonth().toString();
var y:String = new Date().getFullYear().toString();
var h:String = new Date().getHours().toString();
var mm:String = new Date().getMinutes().toString();
var s:String = new Date().getSeconds().toString();
var unique:String = d + m + y + h + mm + s ;
return unique;
}



above code genrate unique number every request genrate new unique number and browser takes this url as a new url in every request. we can implement it.

httpservice.url = "index.php";
httservice.send(num:uniqueNum);


so it will return you always refresh result.