Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

What I have tried:

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

}






}



}
}
}
Posted
Comments
Karthik_Mahalingam 18-Feb-17 0:01am    
what is the issue
narengowtham 18-Feb-17 1:32am    
Hi,
By clicking on check box on grid view I can check in and check out the files in document library.
Requirement:
While checking out the file which was already exists in document library i should get message "The file which is already check-out".

Issue is:
(item.File.CheckOutType== SPFile.SPCheckOutType.Online)

{
Label2.Text = "already exists";

}
This code enable when files were already check out in library .while I am trying to check out the new file I was getting the message that "check out file already exists".
I should not get the message while checking out new file.
narengowtham 18-Feb-17 1:34am    
Sorry mate, i am unable to explain sweet and short.
narengowtham 18-Feb-17 1:45am    
On run time,The file was check out by different users,they have to get message" File check out is already exsists" on same visual web part page.The same user checking out the new file,he/she should not message that "File check out is already exsists".
narengowtham 20-Feb-17 1:10am    
Hi,
I made the logic's through this condition
if(item.File.CheckOutType!=SPFile.SPCheckOutType.None)
This condition will trigger when files are already checked out.
also with another if condition.
if(item.File.CheckOutType=SPFile.SPCheckOutType.None)
This code will trigger when file to check out new file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900