I was working on check in and check out for document library in share point using visual web part.The check in and check out were enabled through program.
Requirement:
By clicking on button repeatedly it has to show "already file are checked in".
issue
While clicking on first attempt I should not get any popup but clicking on second attempt
I have to get message"already file are checked in". pls let me know the logics
My code:
ID
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gridViewRow in GridView1.Rows)
{
CheckBox chkbox=(CheckBox)gridViewRow.FindControl("chk");
if (chkbox.Checked)
{
Label lbl = ((Label)gridViewRow.FindControl("Label1"));
string id = lbl.Text;
SPWeb mySite = SPContext.Current.Web;
SPList list = mySite.Lists["library1"];
SPListItem guid = null;
guid = list.GetItemById(int.Parse(id));
foreach (SPListItem item in guid.ListItems)
{
if (item.File.CheckOutType == SPFile.SPCheckOutType.None)
{
item.File.CheckOut();
}
else if (item.File.CheckOutType== SPFile.SPCheckOutType.Online)
{
Label2.Text = "already exists";
}
}

Yogendra BhardwajPosted Feb 18, 2017, 10:30 AM
GowthamPosted Feb 20, 2017, 1:02 AM
GowthamPosted Feb 18, 2017, 1:43 AM
{
Label2.Text = "already exists";
}
This code is works fine when file is alreday checked out.Even though I was missing some logic for above scenario.
Yogendra BhardwajPosted Feb 17, 2017, 11:26 AM