I have a class that makes a copy of a google doc template file to then merge placeholders with data. The problem is that it's creating the copy in the same folder as the original template file and I can't find a way to copy it to another folder.
Say I have a structure like so in google drive.
Main
TemplateFiles
MainTemplateDoc
Contracts
CopyOfMainTemplateDocAfterBeingMerged
As you can see, the CopyOfMainTemplateDocAfterBeingMerged doc wouldn't be located in the TemplateFiles folder where the original template was, but copied to the Contracts folder.
Is it possible to use the google drive v2 service to move the file after creating the copy? I'm using the .net Google.Apis.Drive.v2 nuget package. Here's the code that I have so far to create the copy.
private string CopyDocument(string documentId, string title)
{
var newFile = new File { Title = title };
var documentCopyFile = driveService.Files.Copy(newFile, documentId).Execute();
return documentCopyFile.Id;
}
You are using Drive API v2.
You want to copy a file to the folder of Contracts.
You have already been able to use Drive API.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
In this answer, I would like to propose the following modification.
From:
var newFile = new File { Title = title };
To:
var newFile = new File {
Title = title,
Parents = new List<ParentReference> {new ParentReference {Id = parentId}}
};
or
var newFile = new File() {
Title = title
};
newFile.Parents = new List<ParentReference>() {new ParentReference() {Id = parentId}};
or
var newFile = new File();
newFile.Title = title;
newFile.Parents = new List<ParentReference>() {new ParentReference() {Id = parentId}};
parentId is the folder ID of the folder Contracts.
Note:
If you want to use Drive API v3, please use new List<string> {folderId} instead of new List<ParentReference> {new ParentReference {Id = folderId}}.
References:
Files: copy
Files: insert
If I misunderstood your question and this was not the direction you want, I apologize.
Related
I'm using VS2015, MVC 5 design model. Creating a link that says "View" to open a PDF file in a new browser tab. It works fine, but the document sub-directory is hard-coded in the controller. I need to pass the document sub-directory + filename to the controller. The document sub-directory is the same as the Model.id . I'm having a difficult time converting the Model.id to a string and concatenating with the filename.
The following code in the view works fine with the hard-coded sub-directory in the controller
<td>#Html.ActionLink("View", "ViewAttachedDoc", "Documents", new { filename = item.filename}, new { target = "_blank" })</td>
But this code does not work
<td>#Html.ActionLink("View", "ViewAttachedDoc", "Documents", new { filename = Convert.ToString(Model.id) + "\" + item.filename }, new { target = "_blank" })</td>
The controller action is:
public FileResult ViewAttachedDoc(string filename)
{
string DocPath = ConfigurationManager.AppSettings["DocPath"];
string path = Path.Combine(DocPath, filename);
return File(path, "application/pdf");
}
TIA,
Tracy
The issue is likely from trying to pass a backslash through the URL. This link of a similar question has that same problem and their solution was to use HttpUtility.UrlEncode(value); and HttpUtility.UrlDecode(value);. Otherwise if that still doesn't work, what error are you getting?
P.S. C# automatically converts / -> \ for retrieving files.
I try to import csv file in my contacts in a new group with javascript or applescript (I will appreciate help in JS).
what I've tried:(I tried lot combinaison of this command)
var contact = Application("Contacts");
var group = contact.Group({
'name':'test'})
var personne = contact.Person()
contact.add(contact.Person())
var g = contact.Group({name : "test"})
contact.add(g)
I tried first to create a new group but nothing become visible in adress book.app
I aim to do File -> new group(cmd+maj+n) and this new group file->import (cmd +o) but with javascript.
You must use the push() command to add an new object (group, person, ...) to the application.
Use the save() command to show the new object in the application.
This script add a new person in a new group:
var contact = Application("Contacts")
var g = contact.Group({name : "test"})
contact.groups.push(g)// add a new group to the application
contact.save() // save and show the group in the application
var personne = contact.Person({firstName : "Ben", lastName : "zzzzzz", organization : "abcd", jobTitle : "President"})
contact.people.push(personne)// add a new person to the application
contact.add(personne, {to : g}) // add personne to the group
contact.save() // save and show the new person in the new group
My team has been using VSTS for 8 months. Now, Our customer is asking to get "Repro Steps" of the work items in VSTS.
Is there any way to get the content of "Repro Steps" without the HTML format?
No, because the Repro Steps value is the rich text that can contain image etc…. So, the value is incorrect if just return the data without HTML format.
However, you can remove HTML tag programing.
Simple code:
public static string StripHTML(string input)
{
return Regex.Replace(input, "<.*?>", String.Empty);
}
var u = new Uri("[collection URL]"");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("[user name]", "[password]")));
var connection = new VssConnection(u, c);
var workitemClient = connection.GetClient<WorkItemTrackingHttpClient>();
var workitem = workitemClient.GetWorkItemAsync(96).Result;
object repoValue = workitem.Fields["Microsoft.VSTS.TCM.ReproSteps"];
string repoValueWithOutformat = StripHTML(repoValue.ToString());
I want get the folder names from server.MapPath in ASP.NET MVC 3 application.
In this action, I have to check (if there exist more folders in a given folder name) if a .jpg file is in that folder and if so, return that folder.
string path = Server.MapPath("Content/");
DirectoryInfo dInfo = new DirectoryInfo(path);
DirectoryInfo[] subdirs = dInfo.GetDirectories();
if (Directory.Exists(path))
{
ArrayList ar = new ArrayList();
// This path is a directory
ar.Add(path);
//ProcessDirectory(path);
}
I'm not sure I've understand the qestion correctly, but I think you want something like
string path = Server.MapPath(YOURPATH);
List<string> files = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
or something like
string path = Server.MapPath(YOURPATH);
List<string> picFolders = new List<string>();
if(Directory.GetFiles(path, "*.jpg").Length > 0)
picFolders.Add(path)
foreach(string dir in Directory.GetDirectories(path, "*", SearchOption.AllDirectories))
{
if(Directory.GetFiles(dir, "*.jpg").Length > 0)
picFolders.Add(dir)
}
As part of an EvenReceiver the itemAdded on a custom List (source) creates a Calendar entry in another List (target).
I now want to add an itemUpdated event so that when the the source List is updated the change is filtered through to the target List.
I am using c# in Visual Studio to develop the Event Receiver.
Can anyone please advise the best way to do this and how I create the link between the two Lists to ensure I can update from source to target?
Thank you.
You will have to udpate the target list yourself...
var sourceItem = this.properties.ListItem;
//you can use other properties to search for the item in the targetlist aswell
string query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where>", sourceItem.Title);
var spQuery = new SPQuery() { Query = query };
var foundItems = targetList.GetItems(spQuery);
if(foundItems.Count == 1)
{
var foundItem = foundItems[0];
//update the properties you want
foundItem["Property1"] = sourceItem["Property1"];
foundItem["Property2"] = sourceItem["Property2"];
foundItem["Property3"] = sourceItem["Property3"];
foundItem.Update();
}
Note that this piece of code is straight out of my head & untested ;-)