samedi 24 janvier 2015

retrieve the document in sharepoint library when retrieving other data it has to retrieve the document also and how to search inside the document

using Microsoft.SharePoint.Client; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Net; using Microsoft.SharePoint;


using Microsoft.IdentityModel.S2S.Tokens; using ClientOM = Microsoft.SharePoint.Client; using System.Text; using candidate_profileWeb.Pages;


namespace candidate_profileWeb { public partial class Default : System.Web.UI.Page {



SharePointContextToken contextToken;
string accessToken;
Uri sharepointUrl;
protected void Page_Load(object sender, EventArgs e)
{

string contextTokenString = TokenHelper.GetContextTokenFromRequest(Request);
if (contextTokenString != null)
{
contextToken =
TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority);
sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
accessToken =
TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken;


Submit.CommandArgument = accessToken;
retrive.CommandArgument = accessToken;

}
if (IsPostBack)
{
sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
}

//Execute a request to add a list that has the user-supplied name.
}


protected void Submit_Click(object sender, EventArgs e)
{
var accesssToken = ((Button)sender).CommandArgument;

if (IsPostBack)
{
sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
}

//Execute a request to add a list that has the user-supplied name.
ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accesssToken);
Web web = clientContext.Web;
ListCollection lists = web.Lists;
List List = clientContext.Web.Lists.GetByTitle("list name");
clientContext.Load(List);

DateTime dt = DateTime.Today;

ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();


List documentsList = clientContext.Web.Lists.GetByTitle("list name");

var fileCreationInformation = new FileCreationInformation();
byte[] documentstream = System.IO.File.ReadAllBytes(browse.PostedFile.FileName);
fileCreationInformation.Content = documentstream;
fileCreationInformation.Url = browse.PostedFile.FileName;
fileCreationInformation.Overwrite = true;
Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
fileCreationInformation);



uploadFile.ListItemAllFields["cname"] = cname.Text;
uploadFile.ListItemAllFields["qualification"] = qualification.Text;
uploadFile.ListItemAllFields["gender"] = gender.Text;
uploadFile.ListItemAllFields["address"] = address.Text;
uploadFile.ListItemAllFields["posting"] = posting.Text;
uploadFile.ListItemAllFields["domain"] = domain.Text;
uploadFile.ListItemAllFields["experience"] = experience.Text;
uploadFile.ListItemAllFields["salary"] = salary.Text;



uploadFile.ListItemAllFields.Update();
clientContext.Load(documentsList);
clientContext.ExecuteQuery();


try
{
clientContext.ExecuteQuery();
}
catch (Exception j)
{
Label2.Text = j.Message;


}
}





protected void retrive_Click(object sender, EventArgs e)
{
var accesssToken = ((Button)sender).CommandArgument;
if (IsPostBack)
{
sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
}


ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accesssToken);
Web web = clientContext.Web;
ListCollection lists = web.Lists;
List List = clientContext.Web.Lists.GetByTitle("list name");
clientContext.Load(List);

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Eq>" +
"<FieldRef Name ='qualification'/> <Value Type ='Text'>" + TextBox1.Text + "</Value>" +

"</Eq></Where></Query></View>";


//{ "here i have to use [AND] command to retrieve another value both same it has to retrieve " }



Microsoft.SharePoint.Client.ListItemCollection items = List.GetItems(camlQuery);
clientContext.Load(items);
try
{
clientContext.ExecuteQuery();
}
catch (Exception er)
{
Label1.Text = er.Message;
}

foreach (Microsoft.SharePoint.Client.ListItem item in items)
{



TableRow tablerow = new TableRow();
TableCell tablecell1 = new TableCell();
TableCell tablecell2 = new TableCell();
TableCell tablecell3 = new TableCell();
TableCell tablecell4 = new TableCell();
TableCell tablecell5 = new TableCell();
TableCell tablecell6 = new TableCell();
TableCell tablecell7 = new TableCell();
TableCell tablecell8 = new TableCell();
TableCell tablecell9 = new TableCell();

tablecell1.Text = item.FieldValues["cname"].ToString();
tablecell2.Text = item.FieldValues["qualification"].ToString();
tablecell3.Text = item.FieldValues["gender"].ToString();
tablecell4.Text = item.FieldValues["address"].ToString();
tablecell5.Text = item.FieldValues["posting"].ToString();
tablecell6.Text = item.FieldValues["domain"].ToString();
tablecell7.Text = item.FieldValues["experience"].ToString();
tablecell8.Text = item.FieldValues["salary"].ToString();


tablerow.Cells.Add(tablecell1);
tablerow.Cells.Add(tablecell2);
tablerow.Cells.Add(tablecell3);
tablerow.Cells.Add(tablecell4);
tablerow.Cells.Add(tablecell5);
tablerow.Cells.Add(tablecell6);
tablerow.Cells.Add(tablecell7);
tablerow.Cells.Add(tablecell8);
tablerow.Cells.Add(tablecell9);
ListTable.Rows.Add(tablerow);

}
}

}
}


I am created document library in sharepoint online and i uploaded data successfully but i have a problem when i am retrieving the ["qualification = TextBox1.Text"] i has to display what all qualification same in the library . It displaying all the data but "document is not retrieved"


And how to search inside the document data using client side program


what i have to do please help me


Aucun commentaire:

Enregistrer un commentaire