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!
Related
I am working on a program that will move files to a database, text files to be exact. The user will have a starting directory and inside will multiple sub folders and files and so on. I want to go through each Folder and sub folder looking for the text files and add them accordingly to the database so it resembles a directory structure in a way. In the program the files are organized such as the folders are "Categories" that are displayed into a tree view.I am only adding the folder names(as Categories) that do contain text files and their subs and so forth. As well I need to figure out where to plug in the adding of the "Category". As of right now I am using a couple of listboxes for my output until I can get it all figured out.
lstfiles.Items.Add(Dir)
For Each file In System.IO.Directory.GetFiles(Dir)
Dim fi As System.IO.FileInfo = New IO.FileInfo(file)
If fi.Extension = ".txt" Then
If lstRootFolderFiles.Items.Contains(file) = False Then
lstfiles.Items.Add(file)
AddFile(file, Gennumber(9999))
End If
End If
Next
For Each folder In System.IO.Directory.GetDirectories(Dir)
lstfiles.Items.Add(folder)
For Each file In System.IO.Directory.GetFiles(folder)
Dim fi As System.IO.FileInfo = New IO.FileInfo(file)
If fi.Extension = ".txt" Then
If lstRootFolderFiles.Items.Contains(file) = False Then
lstfiles.Items.Add(file)
End If
End If
Next
Next
I have gotten so far as to iterate through the directory and get files but it returns folders that are empty. And I need to figure out where I need to put in my addcategory function. And also remember the last one that was added so they can be added as a subcategory.
I think I am making a big mess of it all, or over thinking the whole thing.
Any assistance or guidance would be appreciated.Thank you
The end result that I came up with was much different from my original posting, as it was my way of thinking of how it was going to work. I split up the two main functions. Retrieving the Folders and retrieving the files.
DirEx is the Import Directory, CatID is the Tag of the selected Treenode where the folders are going to added in.
Private Sub DirImport_GetSubDirectories(ByVal DirEx As String, ByVal CatID As Integer)
Try
Dim ClsData As New clsNoteData
'Set the DatabaseFile Property of the class
ClsData.Database = LoadedLibraryDatabase
' Get all subdirectories
Dim subdirectoryEntries() As String = Directory.GetDirectories(DirEx)
' Loop through them to see if they have any other subdirectories
Dim subdirectory As String
For Each subdirectory In subdirectoryEntries
'If the Directory is not Empty
If Not Directory.GetFileSystemEntries(subdirectory).Length = 0 Then
Dim di As DirectoryInfo = New DirectoryInfo(subdirectory)
'Creating Random Number
Dim NewCatID As Integer = GenNumber(9999)
'Call for a new Sub Category
ClsData.NewSubCategoryNode(LoadedLibraryDatabase, NewCatID, CatID, di.Name, -1)
'Get files in the current Directory
DirImport_GetFiles(subdirectory, NewCatID)
'Get the next set of Subfolders
DirImport_GetSubDirectories(subdirectory, NewCatID)
End If
Next
Catch ex As Exception
End Try
End Sub
Private Sub DirImport_GetFiles(ByVal DirEx As String, ByVal CatID As Integer)
Dim Files() As String = Directory.GetFiles(DirEx, "*.txt")
Dim file As String
For Each file In Files
Dim clsNoteData As New clsNoteData
Dim fi As FileInfo = New FileInfo(file)
clsNoteData.Database = LoadedLibraryDatabase
clsNoteData.NewNote_ID = GenNumber(99999)
clsNoteData.NewNote_CatID = CatID
clsNoteData.NewNote_Title = Path.GetFileNameWithoutExtension(file)
clsNoteData.NewNote(False, file)
Next
End sub
So here it is for anyone who may want to do something similar.
Is there any way in VBA to list the files stored in a particular folder on Worksite/iManage by referencing a FolderID?
What I would like to achieve is to get all files and list them in the spreadsheet in column A just like you can get the contents of a folder from an ordinary disk directory.
In imanage the file name would be iManDocument.Description.
Below is what I have come up with so far. I don't know how to move forward with this :(
Dim dmsRoot As IManDMS
Dim dmsSession As IManSession
Dim dmsDatabase As IManDatabase
Dim iFile As IManDocument
Dim iFdr as ImanFolder
DimFname as String
Const ServerName As String = "DMSname"
Const DatabaseName As String = "DatabaseName"
Const ifID as long = "123456"
Set dmsRoot = New ManDMS
Set dmsSession = dmsRoot.Sessions.Add(ServerName)
dmsSession.TrustedLogin
Set dmsDatabase = dmsSession.Databases.ItemByName(DatabaseName)
Set iFlr = dmsDatabase.GetFolder(ifID)
What I normally would do is create a loop
For each iFile in iFlr
Fname = IFile.Description
and put the name in cells one by one but the ImanFolder doesn't seem to have such properties.
Some help wih this would be really appreciated.
IManage folders have a Contents property that contains the items stored in it. You can enumerate through the contents, casting to a IManDocument where possible, and getting the properties from that. Something akin to the following should work:
Dim folderItem As IManContent
Dim currentImanDoc As IManDocument
.... Get your folder
For Each folderItem In currentIManFolder.Contents
FName = folderItem .Description
Next
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
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;
My program needs to read an XML file that a software vendor sent me in order to complete a process. The problem is I cannot tell the program where the file is locate!
When i publish the program and install the program it generates a random folder every time it installs
Location the same folder name is always different
C:\Users\Ray\AppData\Local\Apps\2.0\6ZNVVG8V.C6O\0MELQPL9.LCB\lol-..tion_531c8308fa0ff83d_0001.0000_5a2aee0cd0a667c1
I Have figured out how to get that folder to show by doing this
Dim resourcePath As String = _
System.IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName)
Dim rIndex As Integer = resourcePath.LastIndexOf("\")
resourcePath = resourcePath.Substring(0, rIndex)
Dim filePath As String = System.IO.Path.Combine(resourcePath, "Client.xml")
But the program creates a second folder that it puts the XML and the ICOn file in thats randomly generated but in the same directory.
How do I get the program to look in that folder for the xml?
PLEASE HELP ME !
Ray
You could do this:
Dim query = _
From d In System.IO.Directory.GetDirectories(resourcePath)
Let f = New FileInfo(System.IO.Path.Combine(d, "Client.xml"))
Where f.Exists
select f.FullName
Dim filePath = query.FirstOrDefault()
get list of all files by filter
lblPaymentMode.Location = New Point(lblDate.Right - lblPaymentMode.Width, lblPaymentMode.Location.Y)
Dim mFiles() As String = Directory.GetFiles("Path of folder", "*.xml", SearchOption.AllDirectories)
For i As Integer = 0 To mFiles.Count - 1
Debug.Print(mFiles(i)) 'print name and path of of each file
Next