Featured Posts

How to install and implement Sphinx Search in windows... Follow below steps for install & implement Sphinx. Step 1 - Unzip your zip file to C:[your folder name]. This directory should now include a few files, such as sphinx.conf.in, and sub directories. Step...

Read more

Dynamic CURD Stored Procedures: PHP Script Tired of writing Stored Procedures for regular CURD operations? Here is useful PHP script, which generates the script for Stored Procedures. So no more ooops... Just Copy and execute it. //Code <?php $tableName...

Read more

SharePoint List to JSON Hi Readers, I am back with JSON, as I promised. Let continue from this post: We got a very clean XML form of a SharePoint List with minimal efforts. Lets have more fun with JSON from a SharePoint...

Read more

Copy resource files over all the servers in SharePoint... How is your resource copying feature behaving on your SharePoint Farm? Does it copy all the resource files over all the servers in a SharePoint Farm? No? Here is the solution to this problem. The...

Read more

Well Formatted XML Data From SharePoint List Its really hard to get well formatted XML from SharePoint List either process it for JSON or Ajax stuff. Here is very simple and quick implementation of  Web Service to get the Well formatted XML Data...

Read more

  • Prev
  • Next

How to install and implement Sphinx Search in windows

Category : Framework, Sphinx

Follow below steps for install & implement Sphinx.

Step 1 – Unzip your zip file to C:\[your folder name]. This directory should now include a few files, such as sphinx.conf.in, and sub directories.

Step 2 – Add the sub directories data and log.

Step 3 – Copy the file data C:\[your folder name]\sphinx.conf.in to C:\[your folder name]\sphinx.conf

Step 4 – Open newly created file C:\[your folder name]\sphinx.conf in a any text editor.

Step 5 – Change the database credentials in sphinx.conf.

Step 6 – Find and replace all occurrences of @CONFDIR@/ with C:\[your folder name]\, at least in the uncommented lines (must use forward slash (/) with backslash (\)).

Step 7 – Source and index settings are not need to change for now.

Step 8 – Execute script in MySQL that gives by sphinx i.e. example.sql it just for testing purpose otherwise you can you your DB.

Step 9 – Start cmd.exe as an administrator.

Step 10 – Index the database by entering :
cd c:\[your folder name]\bin\indexer.exe –config c:\[your folder name]\sphinx.conf test1

Step 11 – Install Sphinx as a service by entering:
cd c:\[your folder name]\bin\searchd.exe –install –config c:\sphinx\bin\sphinx.conf –servicename MySearch

Step 12 – Start the service: Go to Control panel > Administrative tools > Services. Right-click on “MySearch ” in the list and click “Start”.

Step 13 – Test the search by entering:
cd c:\[your folder name]\bin\search.exe –config c:\sphinx\sphinx.conf test .
This should result in some matches for the search term “test”.

Step 14 – Copy the Sphinx Search PHP API from C:\[your folder name]\api\sphinxapi.php to your site’s HTML directory, for example C:\xampp\htdocs\[yoursite]\sphinxapi.php.

Step 15 – Create a test PHP file with the following contents:

setServer("127.0.0.1", 9312);
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$s->SetLimits(0, 25);
//Sorts by relevance in descending order (best matches first)
$s->SetSortMode (SPH_SORT_RELEVANCE); //"published asc/desc"
//Insert here text for searching
$result = $s->Query("test");

if ($result['total'] > 0) {
echo 'Total: ' . $result['total'] . "\n";
echo 'Total Found: ' . $result['total_found'] . "\n";
echo '
';
echo '


';
foreach ($result['matches'] as $id => $otherStuff) {
$row = mysql_fetch_array(mysql_query("select * from documents where id = $id"));
extract($row);
++ $no;
echo "


";
}
echo '
No. ID Group ID Group ID 2 Date Added Title Content
$no $id $group_id $group_id2 $date_added $title $content
'; } else { echo 'No results found'; } ?>

Step 16 – Run the file, you get a table of results that include the search term “test”.

NOTE – If service is not start from control panel then try to execute using command prompt.

Dynamic CURD Stored Procedures: PHP Script

Category : MySql, PHP

Tired of writing Stored Procedures for regular CURD operations? Here is useful PHP script, which generates the script for Stored Procedures. So no more ooops… Just Copy and execute it.

//Code
<?php
$tableName = $_GET['table'];
$conn = mysql_connect('localhost', 'root','');
//echo $conn;
mysql_select_db('<DBNAME>', $conn);
$result = mysql_query('select * from `'.$tableName.'`');
$paramList = '(<br/>';
$tableIdField = mysql_field_name($result, 0);
$insertFields = "(";
$insertValues = "(";
$updateList = "";
for($i=0;$i< mysql_num_fields($result);$i++){
$fieldName = mysql_field_name($result, $i);
$fieldType = mysql_field_type($result, $i);
if($i>0){
$insertFields = $insertFields.$fieldName.',';
$insertValues = $insertValues.' _'.$fieldName.',';
}
$updateList = $updateList.' '.$fieldName.'='.' _'.$fieldName.',';
$fieldFormat = '';
$fieldFormat = $fieldFormat.' _'.$fieldName;
$fieldFormat = $fieldFormat.' '.$fieldType;
$fieldFormat = $fieldFormat.' '.',<br/>';
$paramList = $paramList.' '.$fieldFormat;
}
$insertFields = $insertFields.')';
$insertValues = $insertValues.')';
$updateList = $updateList.')';
$paramList = $paramList.')<br/>';
$paramList = str_replace('int','int(11)',$paramList);
$paramList = str_replace('string','text',$paramList);
$paramList = str_replace(',)',')',$paramList);
$insertFields = str_replace(',)',')',$insertFields);
$insertValues = str_replace(',)',')',$insertValues);
$updateList = str_replace(',)','',$updateList);
$spText = '<br/><br/>DELIMITER $<br/>';
$spText = $spText.' <br/>DROP PROCEDURE IF EXISTS Manage'.$tableName.' $<br/>';
$spText = $spText.' <br/>CREATE PROCEDURE Manage'.$tableName.'<br/>';
$spText = $spText.$paramList;
$spText = $spText.' <br/>BEGIN<br/>';
$spText = $spText.' <br/>IF _'.mysql_field_name($result, 0).' = 0 THEN<br/>';
$spText = $spText.' INSERT INTO '.$tableName.' '.$insertFields.' VALUES '.$insertValues.';';
$spText = $spText.'<br/> ELSE<br/>';
$spText = $spText.'<br/> UPDATE '.$tableName.' SET '.$updateList.' WHERE '.$tableIdField.'=_'.$tableIdField.';';
$spText = $spText.' <br/>END IF;<br/>';
$spText = $spText.' <br/>END $<br/>';
$spText = $spText.' <br/>DELIMITER ;<br/>';
echo '<br/><strong>Insert/Update stored Procedure: </strong><br/>';
echo $spText;
//mysql_num_rows($result);
//echo mysql_num_fields($result);
//echo mysql_field_name($result,0);
$spText='';
echo '<br/><br/><br/><br/>';
$spText = '<br/><br/>DELIMITER $<br/>';
$spText = $spText.' <br/>DROP PROCEDURE IF EXISTS Read'.$tableName.' $<br/>';
$spText = $spText.' <br/>CREATE PROCEDURE Read'.$tableName.'<br/>';
$spText = $spText.'(_id int(11))';
$spText = $spText.' <br/>BEGIN<br/>';
$spText = $spText.' <br/>IF _id = 0 THEN<br/>';
$spText = $spText.' SELECT * FROM '.$tableName.';';
$spText = $spText.'<br/> ELSE<br/>';
$spText = $spText.' SELECT * FROM '.$tableName.' WHERE ID = _ID;';
$spText = $spText.' <br/>END IF;<br/>';
$spText = $spText.' <br/>END $<br/>';
$spText = $spText.' <br/>DELIMITER ;<br/>';
echo '<br/><strong>Select All/specific record stored Procedure: </strong><br/>';
echo $spText;
?>
<?php $tableName = $_GET['table']; $conn = mysql_connect('localhost', 'root',''); //echo $conn; mysql_select_db('livelihood', $conn); $result = mysql_query('select * from `'.$tableName.'`'); $paramList = '(<br/>'; $tableIdField = mysql_field_name($result, 0); $insertFields = "("; $insertValues = "("; $updateList = ""; for($i=0;$i< mysql_num_fields($result);$i++){ $fieldName = mysql_field_name($result, $i); $fieldType = mysql_field_type($result, $i); if($i>0){ $insertFields = $insertFields.$fieldName.','; $insertValues = $insertValues.' _'.$fieldName.','; } $updateList = $updateList.' '.$fieldName.'='.' _'.$fieldName.','; $fieldFormat = ''; $fieldFormat = $fieldFormat.' _'.$fieldName; $fieldFormat = $fieldFormat.' '.$fieldType; $fieldFormat = $fieldFormat.' '.',<br/>'; $paramList = $paramList.' '.$fieldFormat; } $insertFields = $insertFields.')'; $insertValues = $insertValues.')'; $updateList = $updateList.')'; $paramList = $paramList.')<br/>'; $paramList = str_replace('int','int(11)',$paramList); $paramList = str_replace('string','text',$paramList); $paramList = str_replace(',)',')',$paramList); $insertFields = str_replace(',)',')',$insertFields); $insertValues = str_replace(',)',')',$insertValues); $updateList = str_replace(',)','',$updateList); $spText = '<br/><br/>DELIMITER $<br/>'; $spText = $spText.' <br/>DROP PROCEDURE IF EXISTS Manage'.$tableName.' $<br/>'; $spText = $spText.' <br/>CREATE PROCEDURE Manage'.$tableName.'<br/>'; $spText = $spText.$paramList; $spText = $spText.' <br/>BEGIN<br/>'; $spText = $spText.' <br/>IF _'.mysql_field_name($result, 0).' = 0 THEN<br/>'; $spText = $spText.' INSERT INTO '.$tableName.' '.$insertFields.' VALUES '.$insertValues.';'; $spText = $spText.'<br/> ELSE<br/>'; $spText = $spText.'<br/> UPDATE '.$tableName.' SET '.$updateList.' WHERE '.$tableIdField.'=_'.$tableIdField.';'; $spText = $spText.' <br/>END IF;<br/>'; $spText = $spText.' <br/>END $<br/>'; $spText = $spText.' <br/>DELIMITER ;<br/>'; echo '<br/><strong>Insert/Update stored Procedure: </strong><br/>'; echo $spText; //mysql_num_rows($result); //echo mysql_num_fields($result); //echo mysql_field_name($result,0); $spText=''; echo '<br/><br/><br/><br/>'; $spText = '<br/><br/>DELIMITER $<br/>'; $spText = $spText.' <br/>DROP PROCEDURE IF EXISTS Read'.$tableName.' $<br/>'; $spText = $spText.' <br/>CREATE PROCEDURE Read'.$tableName.'<br/>'; $spText = $spText.'(_id int(11))'; $spText = $spText.' <br/>BEGIN<br/>'; $spText = $spText.' <br/>IF _id = 0 THEN<br/>'; $spText = $spText.' SELECT * FROM '.$tableName.';'; $spText = $spText.'<br/> ELSE<br/>'; $spText = $spText.' SELECT * FROM '.$tableName.' WHERE ID = _ID;'; $spText = $spText.' <br/>END IF;<br/>'; $spText = $spText.' <br/>END $<br/>'; $spText = $spText.' <br/>DELIMITER ;<br/>'; echo '<br/><strong>Select All/specific record stored Procedure: </strong><br/>'; echo $spText;?>

Pass the Table Name as Query String Parameter

Meet me here

SharePoint List to JSON

Category : C#.Net, SharePoint

Hi Readers,

I am back with JSON, as I promised.

Let continue from this post:

We got a very clean XML form of a SharePoint List with minimal efforts. Lets have more fun with JSON from a SharePoint List.

Its very easy with this code to export List Items from default view  to valid JSON.

Following code gives you the SharePoint List’s default view in the form of a VALID JSON.

    [WebMethod]
    public string ListDataJSON(string ListName)
    {
        string _jsonData = string.Empty;
        XmlDataDocument _xDoc = new XmlDataDocument();
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite _spSite = new SPSite("http://www.codepursuit.com"))
            {
                using (SPWeb _rootWeb = _spSite.RootWeb)
                {
                    SPList _list = _rootWeb.Lists[ListName];
                    DataSet _dsList = new DataSet(ListName.Replace(" ", "") + "Items");
                    DataTable _dtList = _list.GetItems(new SPQuery(_list.DefaultView)).GetDataTable();
                    _dtList.TableName = ListName.Replace(" ", "") + "Item";
                    _dsList.Tables.Add(_dtList);
                    _xDoc = new XmlDataDocument(_dsList);

                    #region JSON Convertor
                    _jsonData = JSONConvertor(_xDoc);
                    #endregion
                }
            }
        });
        return _jsonData;
    }

    private string JSONConvertor(XmlDocument _xDoc)
    {
        string _json = "";
        XmlNode _listNode = _xDoc.DocumentElement;
        _json += "{\"" + _listNode.Name + "\":";
        XmlNodeList _itemNodes = _listNode.ChildNodes;

        _json += "{\"" + _itemNodes[0].Name + "\":[";
        foreach (XmlNode _listItem in _itemNodes)
        {
            _json += "{";
            foreach (XmlNode _field in _listItem.ChildNodes)
            {
                _json += "\"" + _field.Name + "\":\"" + _field.InnerText + "\", ";
            }
            _json += "}";
        }
        _json += "]";
        _json += "}";
        _json = _json.Replace(", }{", "}, {");
        _json = _json.Replace(", }]}", "}]}}");
        return _json;
    }

Meet me here

Copy resource files over all the servers in SharePoint Farm

Category : C#.Net, SharePoint

How is your resource copying feature behaving on your SharePoint Farm? Does it copy all the resource files over all the servers in a SharePoint Farm? No? Here is the solution to this problem.
The basic problem with resource copying is it only copies the resources to application server’s ‘App_GlobalResources’, the rest of servers are simply ignored. To employ the copy on each server, I have taken the SPServerCollection from a SPFarm. Create the network path by using the server name(this can be either hostname or IP Address), simply prefix this server path with application folder from IISSettings and its done. It copies the resources to the network path. Please dont forget to run this code with Elevated Privileges, so that will not give access denied exception.
Please find the code below on feature activate receiver
Code:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Filter to get ‘RESX’ files from 12[14]\Resources
string fileNameFilter = properties.Feature.Properties["FileNameFilter"].Value;
string sourcePath = SPUtility.GetGenericSetupPath(“Resources”);
SPWebApplication app = (SPWebApplication)properties.Feature.Parent;
SPFarm farm = app.Farm;
SPServerCollection _servers = farm.Servers;
foreach (SPUrlZone zone in app.IisSettings.Keys)
{
//Find each server in farm which is related to current web app
SPIisSettings setts = app.IisSettings[zone];
foreach (SPServer _server in _servers)
{
try
{
string destPath = Path.Combine(setts.Path.ToString(), “App_GlobalResources”);
//Added to copy to a Network Path
destPath = destPath.Replace(“:\\”, “$\\”);
destPath = “
\\\\” + _server.Address + “\\” + destPath;
var filters = fileNameFilter.Split(‘,’);
foreach (var filter in filters)
{
string[] filePaths = Directory.GetFiles(sourcePath, filter);
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
//If the web application is not exists on the server will throw exception
//In this case just go ahead with next server
try
{
File.Copy(@filePath, Path.Combine(@destPath, fileName), true);
}
catch (Exception ex)
{
//ErrorHandling.LogMessageToSystemLog(ex.Message + “\nCopy File Error”, System.Diagnostics.EventLogEntryType.Error);
}
}
}
}
catch (Exception exPath)
{
ErrorHandling.LogMessageToSystemLog(exPath.Message + “\nFarm Server Error”, System.Diagnostics.EventLogEntryType.Error);
}
}
}
});
}
catch (Exception ex)
{
//TODO: ADD Excdeption handling logic here
//ErrorHandling.LogMessageToSystemLog(ex.Message + “\nFeature Error”, System.Diagnostics.EventLogEntryType.Error);
}
}

Meet me here

Well Formatted XML Data From SharePoint List

1

Category : C#.Net, SharePoint

Its really hard to get well formatted XML from SharePoint List either process it for JSON or Ajax stuff.

Here is very simple and quick implementation of  Web Service to get the Well formatted XML Data from SharePoint List. Such XML is very easy to use with JSON/AJAX.

[WebMethod]
public XmlDataDocument ListData(string ListName)
{
XmlDataDocument _xDoc = new XmlDataDocument();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite _spSite = new SPSite(“http://www.codepursuit.com“))
{
using (SPWeb _rootWeb = _spSite.RootWeb)
{
SPList _list = _rootWeb.Lists[ListName];
DataSet _dsList = new DataSet(ListName.Replace(” “, “”) + “Items”);
DataTable _dtList = _list.GetItems(new SPQuery(_list.DefaultView)).GetDataTable();
_dtList.TableName = ListName.Replace(” “, “”)+”Item”;
_dsList.Tables.Add(_dtList);
_xDoc = new XmlDataDocument(_dsList);
}
}
});
return _xDoc;
}
To get the SPList data in JSON let’s see in next post.
Thanks for reading.

Meet me here

How to upload greater than 8 MB file on Godaddy server ?

Category : Codeigniter, Hosting, PHP

Some days before, i have faced a issue for uploading large memory size file on godaddy server, though my written PHP code works fine on localhost . I have hosted my web application on Godaddy server.

I have  searched solution on godaddy help center and google, but some where i read using .htaccess we can solve problem.

But i got a solution using php5.ini which works fine for me.

  • I have read somewhere, godaddy server fetch information from php5.ini file. There is a php.ini file exist at root.
  • If we search php5.ini file on fresh hosted site root directory we not found it.
  • So create a file name it php5.ini.
  • Once file create insert following code
  • max_execution_time = 7200
    max_input_time = 7200
    upload_max_filesize = 200M
    post_max_size = 200M
    
  • Then upload that file at root directory.
  • To confirm updated configuration create a PHP and name as phpinfo.php add following code
    <?php phpinfo (); ?>
    

    code in that file . Then upload it and hit on; www.your_domain.com/phpinfo.php

    it will show



Now you can upload files upto 200 MB.

Hope this answer may useful.

Localization in CodeIgniter.

Category : Codeigniter

CodeIgniter has lot of  useful libraries and Classes, one of them is Language class.

Here we are going to create simple localization application using CodeIgniter  Language Class.

Note : We used here CodeIgniter 2.0.3 version for this application.

I am assuming that you know basic installation of CI application, if no please have look on CodeIgniter from Scratch.

Lets start with our example; I have named  our application ci_localization .

  • Language File:

We are going to put our language files in Language folder which located at (ci_localization/application/language).

It looks as below.

Language folder structure

In our application we have  six languages viz. Arabic, English, French, Polish, Russian, Turkish.

In each folder we have file having name codepursuit_lang.php contains respective languages text.

It has simple syntax:

$lang['language_key'] = "The actual message to be shown";

Our english/codepursuit_lang.php has code as follows;

$lang['htmldir'] = "ltr"

$lang['title'] = "English Font Page";
$lang['name'] = "Name:";
$lang['contact'] = "Contact:";
$lang['company'] = "Company:";
$lang['country'] = "Country:";

We need to make same files as per required languages. Just we have to write  right side part in required language.

  • Controller:

Now lets create a controller for our ci_localization application name it ctrlLocalize.

As we are going to just display a single view for localization, we need to write code in index function.

Here is our controller ctrlLocalize.php code;

class ctrlLocalize extends CI_Controller {
public function index()
{

//get posted language
if(isset($_POST['language']))
{
$language = $_POST['language'];
}
else
{
$language = "english";
}

// load language file
$this->load->helper('language');
$this->lang->load('codepursuit', $language);

$this->load->view('localize');
}
}

We got posted language using below code;

//get posted language
if(isset($_POST['language']))
{
$language = $_POST['language'];
}
else
{
$language = "english";
}

After that we have loaded selected language;

// load language file
$this->load->helper('language');
$this->lang->load('codepursuit', $language);

And finally we load our view localize.php.

  • View:

Lets create a view for our application,

To display selected language text simply we have to use

 lang('language_key')

function.

Like,

 <?=lang('contact')?> 

And our final view localize.php,

<html xmlns="http://www.w3.org/1999/xhtml" dir="<?=lang('htmldir')?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=lang('title')?></title >
</head>

<body>
<p><h4><?=lang('title')?></h4> </p>
<table width="50%">
<tr>
<td><?=lang('name')?></td>
<td width="5%">&nbsp;</td>
<td>Vikrant Kumbhar</td>
</tr>
<tr>
<td><?=lang('contact')?></td>
<td width="5%">&nbsp;</td>
<td>XXX-XXX-XXXX</td>
</tr>
<tr>
<td><?=lang('company')?></td>
<td width="5%">&nbsp;</td>
<td>RedSoiltech</td>
</tr>
<tr>
<td><?=lang('country')?></td>
<td width="5%">&nbsp;</td>
<td>India</td>
</tr>
</table>

<form action="<?php echo base_url(); ?>" name="language" method="post">
<select style="width: 200px;" name="language" onchange="this.form.submit();">
<option value="english">-- Select Language --</option>
<option value="english">English</option>
<option value="turkish">Turkish</option>
<option value="french">French</option>
<option value="russian">Russian</option>
<option value="arabic">Arabic</option>
</select>
</form>
</body>
</html>

And our application look as,

view_demo

Error in Formula “Group_Selection” String is required here.

1

Category : Crystal Report

It generates the error because of the report field schema and passed value are not matched.

To solve the error you have to modified the Group selection formulas thats steps are as follows.

Step 1 – Select Expert option as shown in below Image.

Select Expert

Step 2 – Double click on that field that appear on error please see below Image.

Choose Field

Step 3 – Click on show formuls button and we have to edit or add new a formula as per report schemas.

How to use INTERSECT operand in sql OR How to get distinct values that are returned by both the query on the left and right sides?

Category : SQL

Some time we want to get distinct values from two query then use INTERSECT operand between two query.
The following query returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand

Select ID from tabel1 where table1.name like 'ABC'
INTERSECT
Select ID from tabel2 where table2.name like 'ABC'

Could not load file or assembly ‘System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′ or one of its dependencies

Category : Hosting

If you are using VS2008, then you need to check following assembly in your web.config :


And if you are still facing same error,
then you need to change the “bindingRedirect oldVersion” range for the System.Web.Extensions.dll in the “runtime”
section in the web.config file from “1.0.0.0-1.1.0.0″ to “1.0.0.0-3.0.0.0″ as shown below :















Your Ad Here