Sunday, October 31, 2010

Delete data items from Sharepoint list

Following code help you to delete the Sharepoint list items row by row.

private void DeleteRows()
{

string SPSiteName = "http://localhost";
string SPWebName = "";
string SPListName = "some_list";

try
{
using (SPSite site = new SPSite(SPSiteName))
{
using (SPWeb web = site.AllWebs[SPWebName])
{
SPList list = web.Lists[SPListName];
SPListItemCollection listitems = web.Lists[SPListName].Items;


int count = 0;

for (int i = list.Items.Count - 1; i >= 0; i--)
{
listitems.Delete(i);
count++;
}
MessageBox.Show(count+" rows deleted successfully");

}
}
}
catch (Exception ee)
{
MessageBox.Show("Incorrect Data");
}
}

Display Sharepoint list items in a grid view.

This article describes how to display sharepoint list items in a grid view, i.e C# windows application gridview.
Start a C# windows application and add a Button and a DataGridView to display the list items.
Call the following method on the button click event.

private void ViewData()
{
string camlquery;

string SPSiteName = "http://localhost";
string SPWebName = "";
string SPListName = "some_list";

try
{
using (SPSite site = new SPSite(SPSiteName))
{
using (SPWeb web = site.AllWebs[SPWebName])
{
SPList list = web.Lists[SPListName];
SPQuery query = new SPQuery();

//mention the query as you want

camlquery = " ";
query.Query = camlquery;
SPListItemCollection listitems = list.GetItems(query);
DataTable dt = listitems.GetDataTable();
dataGridView1.Visible = true;
dataGridView1.DataSource = dt;

MessageBox.Show(listitems.Count + " rows");

}
}
}
catch (SPException ee)
{
MessageBox.Show("Incorrect data entered");
}
}

Don’t forget to add the Microsoft.SharePoint reference.

Thursday, May 6, 2010

Capture the screen activity and save as a video file in C#

There are some software you may find to capture the screen as a video file. For example camstudio, etc. Here a piece of code written in C# to capture the screen activity and save as a video file in specified location. It is very useful in some control application to watch the controllers’ activity for later requirements.

To run this program you have to install windows media encoder 9 series. Windows media encoder is freely available media encoder developed by Microsoft which enables the developer to capture screen activities. You can download windows media encoder 9 here.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WMEncoderLib;
using WMPLib;
using System.Threading;


namespace WindowsFormsApplication1
{


public partial class Form1 : Form
{

private WMEncoder m_encoder;
private IWMEncProfile m_profile;



public Form1()
{
InitializeComponent();
}


private void startCapture(string targetFileName)
{
m_encoder = new WMEncoderClass();


IWMEncSourceGroup SrcGrp;
IWMEncSourceGroupCollection SrcGrpColl;
SrcGrpColl = m_encoder.SourceGroupCollection;
SrcGrp = SrcGrpColl.Add("sourceGroupName");

IWMEncSource SrcVid = null;
IWMEncSource SrcAud = null;

SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcVid.SetInput("screenCap://screenCapture1", "", "");

SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
SrcAud.SetInput("Device://Default_Audio_Device", "", "");

IWMEncProfileCollection ProColl = m_encoder.ProfileCollection;
int ILength = ProColl.Count;
string name;
for (int i = 0; i <= (ILength - 1); i++)
{
name = ProColl.Item(i).Name;
m_profile = ProColl.Item(i);

}


SrcGrp.set_Profile(m_profile);

IWMEncDisplayInfo Descr;
Descr = m_encoder.DisplayInfo;
Descr.Author = "mohamed";
Descr.Copyright = "copyright";
Descr.Description = "desccription";
Descr.Rating = "rating";
Descr.Title = "my title";

IWMEncAttributes Attr;
Attr = m_encoder.Attributes;
Attr.Add("URL", "www.google.com");

IWMEncFile File;
File = m_encoder.File;
File.LocalFileName = targetFileName;

if (null != SrcVid)
{
((IWMEncVideoSource)SrcVid).CroppingBottomMargin = 1;
((IWMEncVideoSource)SrcVid).CroppingTopMargin = 1;
((IWMEncVideoSource)SrcVid).CroppingLeftMargin = 1;
((IWMEncVideoSource)SrcVid).CroppingRightMargin = 1;
}

try
{
m_encoder.Start();
}
catch (Exception ex)
{
MessageBox.Show("could not capture " + ex.Message);

}
}

}
}

Add WMEncoderLib to the reference. Call the method startCapture and pass the location to save the video file.
Ex: Form1 f = new Form1();
f.startCapture("C:/Users/MOHAMED/Desktop/az.wmv");

Monday, January 25, 2010

The Formation of the Universe

Until the mid 20th century the view of the world was thought as infinite, had existed for ever and the functions of the world will continue forever. It was believed that the universe has no beginning and no end. However as science and technology progress during the 20th century, the above model has been completely uprooted. Through numerous experiments, observations and calculation conducted by some of the world's most prominent thinkers, modern physics has proven that the universe did indeed have a beginning, that it came into being from nothing in a single moment in a huge explosion.
Furthermore, it has been established that the universe is not fixed and static, as materialists still stubbornly maintain. On the contrary, it is undergoing a constant process of movement, change and expansion. These recently-established facts all act as nails in the coffin of the static universe theory. Today, all these facts are universally accepted by the scientific community.

The origin of the universe is described in the Qur'an in the following verse:
He created the heavens and the Earth from nothing. (Qur'an, 6:101)

As stated earlier, the conclusion that astrophysics has reached today is that the entire universe, together with the dimensions of matter and time, came into existence as a result of a great explosion that occurred a long time ago. This event, known as "The Big Bang," is the catalyst for the creation of the universe from nothingness. This explosion, all parties in the scientific community agree, emanated from a single point some 15 billion years ago.

Source: The Creation of the Universe by Harun Yahya

Thursday, August 20, 2009

SCADA

SCADA, Supervisory Control And Data Acquisition, refers to an industrial control system, a system monitoring and controlling a process. SCADA, that’s collects data from various sensors at a factory or remote location and then sends this data to a central computer which manages and controls the data. Now days it is used for wide range of solutions, such as water management systems, electric power, traffic signals, mass transits systems, environment control systems and manufacturing systems.

SCADA system consist of the following subsystems
1. HMI-Human Machine Interface. A system where data is processed and presented to be viewed and monitored by a human operator.
2. RTU- Remote Terminal Unit. Connecting to sensors in the process, converting sensor signals to digital data and sending digital data to the supervisory system.
3. PLC- Programmable Logic Controller. Used as field devices because they are more economical, versatile, flexible, and configurable than special-purpose RTUs.

Monday, August 3, 2009

Nanotube powerd x-rays

Conventional x-ray machines consist of a long tube with an electron emitter, a tungsten filament, at one end and a metal electrode at the other end. The tungsten filament emits electrons when it is heated to 1000 degree Celsius. The electrons are accelerated along the tube and strike the metal, creating x-rays.

Instead of single tungsten emitter, the University of North California (UNC) team uses an array of vertical carbon nanotubes that serve as hundred of tiny electron guns. While tungsten requires times to warm up, the nanotubes emit electrons from their tips instantly when a voltage is applied to them.

A company called Xintek in Research Triangle Park, NC, to commercialize the technology. Xintek has team with Siemens to form a joint-venture company.

Taking clear, high-resolution x-ray images of body organs is much easier with the new multi-beam x-ray source. Conventional computerized tomography (CT) scan machines take a few minutes to create clear 3-D images using x-ray. Because the radiation is coming from one point in space, the machine has to move the [electron] source and detector around the object. The x-ray emitter fires while the tube moves. The motion of the heart and lungs can blur images, so a CT scanner takes hundreds of pictures that are synthesized to reconstruct a 3-D image. It speeds up organ imaging, takes sharper images, and could increase the accuracy of radiotherapy so it doesn't harm normal tissue.

Monday, June 1, 2009

Create .jar file

I developed "Ration Data Entry System" for Sri Lanka Army, during my training at DMS Ltd.
The system developed using java, Oracle and HSQLDB. This project contain so many third party libraries such as iText.jar, Hsqldb.jar, etc...
The Netbeans IDE supports to build the jar files. It creates the jarfiles and MANIFEST but the problem is the classpath for the third part libraries are set to out side thr jar file. I needed just one jar file to deliver the produsct. So follow the following procedure.

1. Created an executable JAR file with the application’s CLASS files in it. Name this “main.jar”
jar cfm main.jar manifest.txt *.class
2. Created three directories: MAIN, LIB, and BOOT
3. Placed “main.jar” file in the MAIN directory
4. Placed the jar files that the main application depends on in the LIB directory
5. Created a new JAR file out of the MAIN and LIB directories. Name this one “application.jar”.
jar cf application.jar main lib
6. Extract the contents of the “one-jar-boot.jar” file into the BOOT directory(one-jar-boot.jar is a third party jar file, can download)
7. Navigated to the BOOT directory, and update the “application.jar” file with the following:
jar -uvfm ../application.jar boot-manifest.mf *.*

My “application.jar” file is now be executable.
It is running when moving the "application.jar" to another directory or another computer too.

done.