4
Answers

How to get checked out files from document library

Gowtham

Gowtham

7y
311
1
So for:
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:


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="350px" style="margin-left: 144px; margin-top: 112px">

<columns>
<asp:templatefield>
<headertemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="chkboxSelectAll_CheckedChanged"/>

<itemtemplate>
<asp:checkbox ID="chk" runat="server">


<asp:templatefield>
<headertemplate>
ID

<itemtemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'>


<asp:HyperLinkField HeaderText="Documents" DataTextField="Title" DataNavigateUrlFields="URL"/>




<asp:Label ID="Label2" runat="server" Text="">


<asp:Button ID="Button1" runat="server" style="margin-left: 157px; margin-top: 19px" Text="CheckIn" Width="78px" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" style="margin-left: 57px" Text="CheckOut" />



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";

}






}
 

Answers (4)