Sharepoint 2013 How to add properties to Document Set being created - vb.net

I am using Sharepoint 2013 ECM to upload new document sets to a list programatically in VB.NET/C#
I am successfully creating the document set, but can not find any documentation on how to add the properties/metadata to that uploaded document set. The Folder the document set will upload to already has the properties pre-defined. I just need to set them.
The code below creates the new document set. But there is zero information I can find on the internet on how to add properties from this. Sharepoint 2010 libraries allow the DocumentSet.Create to contain a properties field, but 2013 does not appear to.
Dim context As ClientContext = New ClientContext("URL")
context.Credentials = New NetworkCredential("Username", "Password")
'Get the document library in which the document set has to be created
Dim list As List = context.Web.Lists.GetById(New Guid("dc9e7aa5-5ac3-499c-a967-fa8f04bf1c90"))
'Get the parent folder where the document set has to be created
Dim parentFolder As Folder = list.RootFolder
'Get the "Document Set" content type by id (Document Set content type Id : 0x0120D520) for the document library
Dim ct As ContentType = context.Web.ContentTypes.GetById("0x0120D520")
context.Load(ct)
context.ExecuteQuery()
'Create a new document set
'A new document set will be created in "Documents" library as "Test Document" under which you can add the documents
DocumentSet.Create(context, parentFolder, dsName, ct.Id)
context.ExecuteQuery()

Once the document set is created, you could set its properties via list item associated with a document set
Example
Using context = New ClientContext(webUrl)
context.Credentials = credentials
'Create a document set
Dim list As List = context.Web.Lists.GetByTitle("Documents")
Dim parentFolder As Folder = list.RootFolder
Dim ct As ContentType = context.Web.ContentTypes.GetById("0x0120D520")
context.Load(ct)
context.ExecuteQuery()
Dim result = DocumentSet.Create(context, parentFolder, dsName, ct.Id)
context.ExecuteQuery()
'Set DocSet properties
Dim docSetUrl = result.Value
Dim folder = context.Web.GetFolderByServerRelativeUrl(docSetUrl)
folder.ListItemAllFields("DocumentSetDescription") = "Orders 2016"
folder.ListItemAllFields.Update()
context.ExecuteQuery()
End Using
Result

you have to set the properties on the Item property of the Document Set object. Like this (sorry for c# code):
DocumentSet myDocSet = DocumentSet.Create(x, x, x, x):
SPListItem myDocSetItem = myDocSet.Item;
myDocSetItem[property] = value;

Related

How to call PDPageRelease API to release pdf?

Here is my code.
Public Function GetPDFLastTwentyText(ByVal pstrPdfFilename As String) As String
Dim PDDoc As Object
Dim CAcroRect As New Acrobat.AcroRect
Dim PDPage As Acrobat.AcroPDPage
Dim PDTxtSelect As Acrobat.AcroPDTextSelect
Dim CArcoPoint As Acrobat.AcroPoint
Dim iNumWords As Integer
Dim iMax As Long
Dim arPdfLines() As String
Dim i As Integer
Dim fso As FileSystemObject
GetPDFLastTwentyText = ""
Set fso = New FileSystemObject
If fso.FileExists(pstrPdfFilename) Then
Set PDDoc = CreateObject("AcroExch.PDDoc")
PDDoc.Open pstrPdfFilename
Set PDPage = PDDoc.AcquirePage(PDDoc.GetNumPages() - 1)
Set CArcoPoint = PDPage.GetSize()
CAcroRect.Top = CArcoPoint.y
CAcroRect.Left = 0
CAcroRect.Right = CArcoPoint.x
CAcroRect.bottom = 0
Set PDTxtSelect = PDDoc.CreateTextSelect(PDDoc.GetNumPages() - 1, CAcroRect)
...
PDDoc.Close
End If
Set fso = Nothing
Set PDTxtSelect = Nothing
Set CAcroRect = Nothing
Set CArcoPoint = Nothing
Set PDPage = Nothing
Set PDDoc = Nothing
End Function
I have no idea to use this API.
PDPageRelease()
And Is there official document about this API?
Here is the Description that I find in adobe's API document.
PDPage PDDocAcquirePage(PDDoc doc, ASInt32 pageNum)
Gets a PDPage from
a document. It increments the page's reference count. After you are
done using the page, release it using PDPageRelease(). If
PDPageRelease() is not called, it could block the document containing
the page from being closed. To avoid such problems, use the
CSmartPDPage class, as it ensures that the page is released as it goes
out of scope.
It mention that It should call this API after you call 『AcquirePage』.
Using VBA or other scripting languages you work with OLE Automation. The description you will find "Acrobat Interapplication Communication Reference".
There is no PDPageRelease() element. PDPageRelease() belong to the plugin API. A plugin can only be written in C#.
If you only want to close the document, without closing Acrobat you can use the following code instead of "PDDoc.Close". Br. Reinhard
Set AForm = CreateObject("AFormAut.App") '//connect to Form API
exe = "app.execMenuItem('Close');" '//write js-code to variable
AForm.Fields.ExecuteThisJavaScript exe '//execute js-code

subfolder Creation in google drive (VB.net)

I want to create a folder with a subfolder in google drive using vb.net.
I managed to create the folder , but not the subfolder.
Here is my code
Public Sub createfolder()
Dim dossier = New Google.Apis.Drive.v2.Data.File()
dossier.Title = dat_sauv.SelectedItem 'title from combobox in forms
dossier.MimeType = "application/vnd.google-apps.folder"
Dim rep = Service.Files.Insert(dossier)
rep.Fields = "id"
Dim file = rep.Execute()
'sub folder Creation
Dim subfolder = New Google.Apis.Drive.v2.Data.File()
'title from radio button in forms
If (VT.Checked = True) Then
subfolder.Title = VT.Text
ElseIf (vm.Checked = True) Then
subfolder.Title = VM.Text
ElseIf (VI.Checked = True) Then
subfolder.Title = VI.Text
Else
subfolder.Title = VF.Text
End If
subfolder.MimeType = "application/vnd.google-apps.folder"
Dim res = Service.Files.Insert(subfolder)
res.Fields = "id"
Dim fil = res.Execute()
dossier.Parents = subfolder
end sub
any help please
Based from this thread, you should have first a parents folder. You need to search for the parent root ID. The parents property can be used when creating a folder as well to create a subfolder.
Here's a related posts:
Dynamically Create Folders and Subfolders
To create a subfolder to a particular folder, you should specify the
correct ID in the parents property of the file.
"parents": [{"id":"0ADK06pfg"}]
Check this page for
more information
How can I create a new folder with Google Drive API in Python?
You only need a parent ID here if you want to create folder within another folder, otherwise just don't pass any value for that.
If you want the parent ID, you'll need to write a method to search Drive for folders with that parent name in that location (do a list() call) and then get the ID of that folder.
Hope this helps!

How to dynamically get path to HTML file in VSTO project for Outlook add-in

I am creating a simple Outlook 2016 add-in that will allow the users create a new mail message based on a HTML template.
I have created a Ribbon and added a button to it. Here is the click event handler code:
Private Sub btnCreateMail_Click(sender As Object, e As RibbonControlEventArgs) Handles btnCreateMail.Click
Dim app As Application = Globals.ThisAddIn.Application
Dim currentAccount As Account = app.Session.Accounts.Item(1)
Dim mailItem = DirectCast(app.CreateItem(OlItemType.olMailItem), MailItem)
mailItem.SendUsingAccount = currentAccount
mailItem.To = currentAccount.DisplayName
mailItem.BCC = IdentifyContacts()
mailItem.BodyFormat = OlBodyFormat.olFormatHTML
mailItem.Importance = OlImportance.olImportanceLow
mailItem.HTMLBody = GetEmailBody()
mailItem.Subject = "Subject"
mailItem.Display(False)
End Sub
GetEmailBody() function is responsible for reading the template and modify placeholders as required:
Private Function GetEmailBody() As String
Dim strEmailBody As String
Const strTemplatePath = "C:\Users\umute\template.htm"
' Read the template
Using reader As New StreamReader(strTemplatePath)
strEmailBody = reader.ReadToEnd
strEmailBody = strEmailBody.Replace("{TodaysDate}", Date.Now.ToString("dddd dd MMM yyyy"))
strEmailBody = strEmailBody.Replace("{Name}", GetCurrentUser())
strEmailBody = strEmailBody.Replace("{Greeting}", DetermineGreeting())
reader.Close()
End Using
Return strEmailBody
End Function
The above code works perfectly, however, I am not sure how to get the path to the template file dynamically, that is without entering the full path including C:\Users\ etc. This is because I would like to ship the template file with the add-in to avoid relying on the user to keep it in their local hard drive.
I know that in ASP.NET it is possible to use Server.Mappath("~/file.html") to accomplish this but I don't know the equivalent of this when writing an add-in for Outlook.
After hours of trying, I figured out that the correct way to reference a file is to add it as a resource.
I added a new item of type Resource to the project and added the html template to it. Then, accessed the file like this:
Dim strEmailBody As String = My.Resources.AllResources.Template

vb.net client object model: view content from sharepoint 2010 wikipage

On SharePoint 2010 i have many wikipages containing a table. Is it possible to view the content of that page in vb.net using the client object model?
I tried to get the file code using a stream but the text i get is a lot of asp.net code but not the html code/content from that page...
Dim fileAlgemeen As SP.File = Nothing
Dim siteUrl As String = "https://portal.xx.be/sites/kdb"
Dim ctx As New ClientContext(siteUrl)
Dim credentials As NetworkCredential = New NetworkCredential("xx", "xx")
ctx.Credentials = credentials
Dim web As Web = ctx.Web
ctx.Load(web)
ctx.ExecuteQuery()
Dim relativeUrl As String = "/sites/kdb/596/Algemeen.aspx"
Dim file As SP.File = web.GetFileByServerRelativeUrl(relativeUrl)
ctx.Load(file)
ctx.ExecuteQuery()
Dim fileRef = relativeUrl
Dim fileInfo As FileInformation = SP.File.OpenBinaryDirect(ctx, fileRef.ToString())
Using fileInfo.Stream
Using sr As StreamReader = New StreamReader(fileInfo.Stream)
Dim line As String = sr.ReadToEnd()
lbl.Text = line
End Using
End Using
There is no need to read file content since wiki content is stored in associated List Item PublishingPageContent field.
The following example demonstrates how to read and update wiki content using SharePoint CSOM (VB.NET)
Sub Main()
Const siteUrl As String = "https://contoso.sharepoint.com/kb/"
Const userName As String = "username#contoso.onmicrosoft.com"
Const password As String = "password"
Using ctx = New ClientContext(siteUrl)
Dim credentials As NetworkCredential = New NetworkCredential(userName, password)
ctx.Credentials = credentials
'1. Read Wiki content
Dim wikiFile = ctx.Web.GetFileByServerRelativeUrl("/kb/Pages/Welcome.aspx")
Dim wikiItem = wikiFile.ListItemAllFields
ctx.Load(wikiItem)
ctx.ExecuteQuery()
Console.WriteLine(wikiItem("PublishingPageContent"))
'2. Update wiki content
wikiItem("PublishingPageContent") = "<h1>Welcome to the SharePoint!</h1>"
wikiItem.Update()
ctx.ExecuteQuery()
End Using
End Sub
Key Points:
Wiki content is stored in List Item PublishingPageContent field
File.ListItemAllFields property is used to retrieve List Item
associated with File

How to do Mailmerge in Openoffice using Vb.net

Its 5th Question and apart of one I didn't get response from the experts....
Hope this time I will get the helping hand.
I want to do mailmerge in openoffice using Vb.net and I am totally new with openoffice.
I searched on net for some help to understand how to use openoffice with vb.net but all I get is half info.....So can you please help me and give me code for mailmerge in vb.net for openoffice.
Well i have list of workers in DB and there is this facility that if they want to mail to all or some of the workers then they can do it.I have completed this task using Microsoft Office now as a Add in we are providing the facility to perform the same task using Open Office.
What they have to do is just select the List of workers and click on a button and it will automate the mailmerge using the field of those workers data from DB. The Code of mine is as shown below
Public Sub OpenOfficeMail(ByVal StrFilter As String)
Dim oSM ''Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object ''First objects from the API
Dim arg(-1) ''Ignore it for the moment !
''Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
''Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
''Create a new doc
oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
''Close the doc
oDoc.Close(True)
oDoc = Nothing
''Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///C:\Users\Savan\Documents\1.odt", "_blank", 0, arg)
Dim t_OOo As Type
t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager")
Dim objServiceManager As New Object
objServiceManager = System.Activator.CreateInstance(t_OOo)
Dim oMailMerge As New Object
oMailMerge = t_OOo.InvokeMember("createInstance", Reflection.BindingFlags.InvokeMethod, Nothing, _
objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'com.sun.star.text.MailMerge"})
oMailMerge.DocumentURL = "file:///C:\Users\Savan\Documents\1.odt"
oMailMerge.DataSourceName = CreateSource(StrFilter)''Function that will return the datasource name which will be a text file's path
oMailMerge.CommandType = 0
oMailMerge.Command = "file:///C:\Mail.txt"
oMailMerge.OutputType = 2
oMailMerge.execute(New [Object]() {})**---->I am getting Error here**
End Sub