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