mardi 27 janvier 2015

how to retrieve the document from sharepoint document library



Here i copied my code and output. i uploaded documents in SharePoint document library but i can't retrieve the document from the SP document library .



using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.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;


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("Candidate profile");
clientContext.Load(List);

DateTime dt = DateTime.Today;

ListItemCreationInformation listCreationInformation = new ListItemCreationInformation();

List documentsList = clientContext.Web.Lists.GetByTitle("Candidate profile");

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 retrieve_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("Candidate profile");
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>";

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();

/*in that table118 column i want to retrive document from sharepoint document library this is my doubt please how to change this code. text file easily we are converting to string. But how to convert .doc file to string , how to show that document in text box table119*/

tablecell8.Text = item.FieldValues["resume"].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);

}
}

}
}


output:


in that resume column how to retrive the document from sharepoint document library, name, qualification,domain.....and all retriving but document is not retriving. how to convert .doc file to string.








0 commentaires:

Enregistrer un commentaire