SharePoint -- how to get item-id from ListItem? - sharepoint

I'm implementing an Azure function with SharePoint webhook.
When the hook triggered, I could get the ListItem Id like 1 or 2 or 3 etc.
Then I could retrieve the ListItem by following code, so I could get some info like file type & file name:
var listItem = list.GetItemById(1);
cc.Load(listItem);
cc.ExecuteQuery();
How to download item via graph API when I just know list Id? As it needs item-id (string) instead of list id (int).
await graphClient.Sites["site-id"]
.Drives["drive-id"]
.Items["012SCX46B5IUJGUVDKNJGI3LU2....."]
.Content
.Request(queryOptions)
.GetAsync();
item-id is like 012SCX46B5IUJGUVDKNJGI....., but the listItem id is identity like 1 or 2 or 3.
Updates:
Maybe specify the path & file name could resolve the issue. So it didn't need the item-id...
await graphClient.Sites["site-id"]
.Drives["drive-id"]
.Root
.ItemWithPath("Document.docx")
.Content
.Request(queryOptions)
.GetAsync();
Thanks

Related

Retrieve Documents from a Template

I created a template within my DocuSign developer Sandbox that contains one document. I'm using the C# SDK to try and send out an envelope to a user, based on a template.
Here's the code where I retrieve all of the templates.
TemplatesApi templateApi = new TemplatesApi(ApiClient.Configuration);
EnvelopeTemplateResults templateResults = templateApi.ListTemplates(AccountID);
The issue I am having is the EnvelopeTemplateResults does NOT have any documents associated with it.
When I use the REST API using POSTMAN, performing a GET to this URL, I can see that there's an envelopeTemplateDefinition, that has a Document on it, which is the one I want.
My question is, how, using the SDK API, can I get the envelopeTemplateDefinition ?
In order to have the ListTemplates method include the Documents info, you have to set an Include parameter:
var templatesApi = new TemplatesApi(apiClient.Configuration);
var listTemplatesOptions = new TemplatesApi.ListTemplatesOptions { include = "documents" };
var templateResults = templatesApi.ListTemplates(accountId, listTemplatesOptions);
If you are trying to get the Template Definition of a single template, the templatesApi.Get() method can be used with its own set of Include options:
var getTemplateOptions = new TemplatesApi.GetOptions { include = "documents" };
var templateDefinition = templatesApi.Get(accountId, templateId, getTemplateOptions);
Finally, if you're trying to get an actual PDF out of a specific template, that would be the templatesApi.GetDocument() method:
templatesApi.GetDocument(accountId, templateId, documentId);
Where DocumentId is the specific document you want to pull, or "Combined" if you want to pull all the documents in as a single PDF.
Chris, if you are using the v2 API, there's an endpoint:
GET /v2/accounts/{accountId}/templates/{templateId}/documents/{documentId}
you can try it here - https://apiexplorer.docusign.com/#/esign/restapi?categories=Templates&tags=TemplateDocuments&operations=get
the c# SDK inside TemplateAPI has GetDocument() and UpdateDocument() methods

Getting document attachments using Kentico API

I created book store site on Kentico i used only their adminstration and display the data from my website using Kentico API's but am strugled in getting attachment files related to specific document i've got document data with no problem using
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
var documents = tree.SelectNodes("CMS.Product");
need also to get related attachment files like book PDFs.. i've tried to use
DocumentAttachment
AttachmentInfo
AttachmentInfoProvider
classes but i couldn't get the data .. I would appreciate if any one help me in that.
Actually am searching about something like GetAttachment().Where("AttachmentFile","Ënglish File")
You can filter the returned attachments based on their values in columns (CMS_Attachment table) by using a code like this:
var attachment = AttachmentInfoProvider.GetAttachments()
.WhereEquals("AttachmentName", "Englishfile")
.And()
.WhereEquals("AttachmentExtension", "jpg")
.TopN(1)
.FirstOrDefault();
if (attachment != null)
{
// attachment was found
}
This code will get one .jpg file where attachment name equals to "EnglishFile"
Solved after using something like
var Attachment = AttachmentInfoProvider.GetAttachments(226, true);
This is from Kentico documentation. This example shows how to add an attachment and modify its metadata. You can ignore that part.You will have to make it generic to work for all examples.
Kentico 9 API Links
// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Gets a page
TreeNode page = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/Articles", "en-us");
if (page != null)
{
// Gets an attachment by file name
AttachmentInfo attachment = DocumentHelper.GetAttachment(page, "file.png", tree);
// Edits the attachment's metadata (name, title and description)
attachment.AttachmentName += " - modified";
attachment.AttachmentTitle = "Attachment title";
attachment.AttachmentDescription = "Attachment description.";
// Ensures that the attachment can be updated without supplying its binary data
attachment.AllowPartialUpdate = true;
// Saves the modified attachment into the database
AttachmentInfoProvider.SetAttachmentInfo(attachment);
}

How can I retrieve template id from docusign envelope

I have created a DocuSign envelope from template. I have stored the envelope id for future operations. Using this envelope id I can only retrieve the envelope that I have created but I need the template id too. Is there any way to retrieve the template id from envelope or FolderItems? Please help :(
I'm not sure if you create an envelope from a Template if the templateId is saved as meta data anywhere in the envelope (I don't believe it is). As such you can simply do that yourself - try using Envelope Custom Fields to store the templateId at the time of creation, and that templateId will then be stored as meta data on that envelope throughout it's lifecycle.
Do a search in the DocuSign API Documentation to find out more about "Envelope Custom Fields". For example, here is the page for how to create them.
Thank you #Ergin. I have tried to implement your idea and it is working. But there are some other issues whatever I have done. I am sharing some parts of my code.
//Getting available folder list of my DocuSign account.
DocuSignServiceRef.AvailableFolders folders = DocuSignHelper.GetDocuSignServiceClient().GetFolderList(new DocuSignServiceRef.FoldersFilter { AccountId = DocuSignHelper.UserID });
//Creating a FolderFilter item to get folder items using this filter.
DocuSignServiceRef.FolderFilter filter = new DocuSignServiceRef.FolderFilter();
filter.AccountId = DocuSignHelper.UserID;
filter.FolderTypeInfo = new DocuSignServiceRef.FolderTypeInfo();
filter.FolderTypeInfo = folders.Folders[1].FolderTypeInfo; //Filter Send Items
//Getting sent items
DocuSignServiceRef.FolderResults results = DocuSignHelper.GetDocuSignServiceClient().GetFolderItems(filter);
if (results != null && results.ResultSetSize > 0)
{
foreach (DocuSignServiceRef.FolderItem item in results.FolderItems)
{
foreach (DocuSignServiceRef.RecipientStatus recipient in item.RecipientStatuses)
{
//Filtering items by Recipient
if (recipient.Email.Equals(RecipientEmail))
{
//Getting envelope of the folder item
DocuSignServiceRef.Envelope sentEnvelope = DocuSignHelper.GetDocuSignServiceClient().RequestEnvelope(item.EnvelopeId, false);
if (sentEnvelope.CustomFields != null)
{
//Checking envelope's custom fields for template id
foreach (DocuSignServiceRef.CustomField customField in sentEnvelope.CustomFields)
{
if (string.Equals(customField.Name, "TemplateID"))
{
if (customField.Value == "{CurrentTemplateID}")
{
HasAlreadySignedSameTemplate = true;
//I will not request the recipient for another signature on same template.
}
}
}
}
}
}
}
}
The above code is working for me. But it is taking too much time to load all Sent items. I can't see any way to set recipient information in FolderFilter. If I can set the recipient's email in filter at the first while I am loading Sent Items then time will be saved for me. Otherwise this code will get unusable.
Have you any idea about modifying my implementation?
If you are creating envelopes with a REST call you can retrieve the info with a call templatesv2/accounts/:accountId/envelopes/:envelopeId/templates
Have a go in the envelope tab. I noticed that envelopes created with a SOAP sdk don't have this information filled in.

List 'MyList' does not exist at site with URL

I am trying to make a query on a SPList but I got an error saying that List doesn't exist.
How can I read the current context in the proper way ?
Is somehow a deployment issue ?
var clientContext = new SP.ClientContext.get_current();;
var oList = clientContext.get_web().get_lists().getByTitle("MyList");
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="SearchUserName" /><Value Type="Text">' + loginName + '</Value></Eq></Where></Query></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args) {
//do something
}), Function.createDelegate(this, function (sender, args) {
//log error
}));
I get the error: List 'MyList' does not exist at site with URL '.... site path'
What am I doing wrong? Is there another way of reading the current context?
You could have run into a simple problem which tripped me up:
When you use getByTitle() you need to use the List's display name,
Is your list display name "MyList" or might it be "My List"?
The List 'Title' = List Display Name (Often has spaces)
The List 'Name' = List Internal Name (usually no spaces or special characters)
To find the display name look at what the list is called in the "Site Contents" page.
To find the internal name, look at the URL when you hover over (or click) the List name in "Site Contents".
Try get_web().get_lists().getByTitle("My List");
Remember SharePoint considers each subsite a seperate site. If your code runs on the root of your SharePoint site, but the lists resides in a subsite, your code will not work. You would then need to specify the site when setting your client context.
Are you sure that get_current is actually returning the correct context?
It might be safer to specify the context.
Also, you could use the lists ID instead of the name then get by ID instead.
After I ran into the same problem, I realized my mistake was the following :
I was running Sharepoint's workbench with the root URL of my domain
So I was running workbench with URL
https://mydomainname.sharepoint.com/_layouts/15/workbench.aspx
While I should have used
https://mydomainname.sharepoint.com/sites/myfirstsite/_layouts/15/workbench.aspx

Deleting Orchard CMS HtmlWidget in code

I have a HtmlWidget with an IdentityPart with an Id value like "/Identifier=40b3f227-61af-4d8b-95c9-53bd6021a70e".
<HtmlWidget Id="/Identifier=40b3f227-61af-4d8b-95c9-53bd6021a70e" Status="Published">
<IdentityPart Identifier="40b3f227-61af-4d8b-95c9-53bd6021a70e" />
....
What would be the right way to delete a widget like this in code?
I assume we grab the object using the contentmanager somehow and delete or unpublish it. But I am not sure about the exact mechanics of doing that. Would appreciate an example and some guidance on the approach.
Basically you retrieve the item the item using the content manager as you have suggested. For example if you wanted to retrieve the item by its identity:
var item = _contentManager.Query<IdentityPart, IdentityPartRecord>()
.Where(c => c.Identifier == "40b3f227-61af-4d8b-95c9-53bd6021a70e")
.Slice(0, 1).FirstOrDefault();
Then you pass the retrieved content item back to the content manager to remove or unpublish:
if (item != null)
{
//delete the item - remains in the db but is no longer a draft or published
_contentManager.Remove(item.ContentItem);
//or unpublish
_contentManager.Unpublish(item.ContentItem);
}

Resources