Autodesk BIM360: Create Folder and manage permission - c#

I want to create a new Folder in my BIM360 Project by using the C# SDK. Unfortunately, I do not manage to get a ResourceId to define my parent folder.
I tried it like this:
CreateFolder folder = new CreateFolder();
string root_folder = "...";
folder.Data.Relationships.Parent.Data.Id = root_folder;
But the parent id must be from type ResourceId and I only have a string which contains the id. Until now, I have not found a conversion between string and resource id(ResourceId only supports the standard-constructor)
I have also tried to make a GET request on the root folder to receive all its information. But there I also receive an id as a string.
So how am I supposed to create a resource id for my folder?
And just one little additional question: If I succeed in creating a folder, how can I manage the permission? Is it even possible to do so via webservice?
Thanks in advance

I want to create a new Folder in my BIM360 Project by using the C# SDK
As of August/2017, to create a BIM 360 Docs folder you need to POST Command with this JSON body. In any case, the resource id is the parent folder, it must be another folder, either one default folder on BIM 360 Docs (e.g. Plans) or topFolder on BIM 360 Team.
But there I also receive an id as a string. So how am I supposed to
create a resource id for my folder?
The parent full href can be spliced by / (forward slash) so you can access the parent folder. This sample demonstrates it.
If I succeed in creating a folder, how can I manage the permission? Is
it even possible to do so via webservice?
Again, as of August/2017, we cannot manage permissions by API.

Related

Using Realm Sync with Azure Functions

I'm trying to use Realm Cloud in an Azure Function but it keeps giving me an error:
make_dir() failed: Permission denied Path: /realm-object-server/
Is there a way to configure Azure Functions to have permissions to create files? I'm new to Azure Functions, this is my first one so I'm not really sure of all the particulars.
I have found one solution to this. Inside Azure function, you can only create any file or folder inside the temp folder. So if you use following sync configuration, it should work. It worked for me.
var configuration = new FullSyncConfiguration(new Uri("/~/<your-realm-name>", UriKind.Relative), _realmUser, Path.Combine(Path.GetTempPath(), "realm-object-server"));
So basically, here you are passing the folder name to store the realm locally. If you don't pass the folder name, it will try to store it in a default location where you will get the access error.
I am not familiar with Realm, but functions has permissions to interact with the file system by default. See these links for information on the app service file system (this applies for functions too):
https://learn.microsoft.com/en-us/azure/app-service/operating-system-functionality#file-access
https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system
If the function is deployed using run from package, then the wwwroot is readonly. But since the path in the error message doesn't point to wwwroot, this is probably not the issue.
My best guess is that the code that is failing is trying to write to in an inappropriate location. The information in the links above should help resolve that. Maybe check to see if realm has a config setting that lets you specify which location it should be creating "realm-object-server" in.
You can use
SyncConfigurationBase.Initialize(UserPersistenceMode.NotEncrypted, basePath: Path.GetTempPath());

Retrieve files from cloud public folder

We are creating c# console beta version app for our clients in which they just paste the public folder/file URL of Google drive OR one drive OR drop box OR etc. And in back-end we need to retrieve the file and process it...
I just wanted to know how do we retrieve those cloud files without any prompts for authentication(as given URL will b public, so it should not ask for Id pw)
Any help from you all experts?
With OneDrive, you can use the "shares" API to retrieve a sharing link without authentication.
You just need to encode the sharing URL correctly and then pass that to the API endpoint. The details of encoding are on the page above, but it's just URL safe base64 encoding.
GET https://api.onedrive.com/shares/{encoded_sharing_url}/root/content
The API will return the content of the file.
Edit: I got the URL slightly wrong. The /shares/ API returns a "sharing root" which looks somewhat like a drive object. To access the actual shared file, you need to add /root before the /content part of the path. I've updated this above.

How can i get folder id of folders inside another folders in onedrive?

StringBuilder requestUri = new StringBuilder();
requestUri.AppendFormat(
"https://apis.live.net/v5.0/me/skydrive/files?access_token={0}",
propriedades["access_token"]);
WebClient myWebClient = new WebClient();
string json = myWebClient.DownloadString(requestUri.ToString());
cloud = new JavaScriptSerializer().Deserialize<Cloud>(json);
in this Json appears only informations of folders in root, like name, id..
How can i get folder id of folders inside another folders in onedrive? Using JSON i just can see folders id of folders in root, i cannot see folders id of folders inside another folders. For example, i have a folder id in root with name "Library" and inside this folder i have two folders with names "Book1" and "Book2", how can i get the folders id of these folders?
To answer the direct question that you have, you will need to traverse the folders on your own. The API calls only retrieve for the current level of folder structure. They don't work like a Windows File system does
Additionally I agree with Fals that it might be easier to use APIs that make it nicer for you.
NOTE: Use the folder endpoint if looking at folders for ease of use.
Here is the documentation as well.
You should use the OneDrive C# API or OneDrive JavaScript API, given that you need the JSON. The API is avaible at:
Working with Microsoft OneDrive folders and files

How to extract name/data from database and use it as my folder name which is created dynamically in asp.net c# using server.MapPath()?

I have used AjaxFileUpload to upload multiple image files. Now i want to store the uploaded images inside rootfolder>subfolder.
The rootfolder is in the name of the user.
The rootfolder is created dynamically by taking the session of the user who has logged in
Like this:
string username = Session["username"].ToString();
I am able to create this folder and save images in it. but i want to save it in subfolder.
the subfolder is also created dynamically but this time i have to take the value(id) from the database and name the folder by that id name. (this is so that i can refer to the database)
I know how to create a new folder using Server.MapPath();
Here is the code for it in brief
using System.IO
if (Directory.Exists(Server.MapPath(uploadPath))) return;
else Directory.CreateDirectory(Server.MapPath(uploadPath));
where uploadPath is the folder's name i want to create dynamiclly.
but how do I include the subfolder too in my Server.MapPath() so as to make my path as rootfolder/subfolder ?
Small example to make the question understandable.
I am a seller. I have posted 4 ads online.
Now when i am posting my 5th ad i want to include many images.
these images should be saved in the folder
Seller/5/imagename.jpg.
(where Seller is the username(main folder), 5 is the advertID in the database and the name of the subfolder)
How do i do this? Please help.
I am using asp.net c#
As far as I know, you can't do one statement to create folder and subfolders because you need the folder to be created first.
You have all of the code you need, you just need to repeat it. Check to see if the main folder (username) exists. If it doesn't create it, if it does, check to see if the subfolder exists. If it doesn't, create it.
Just work through that logic and you'll be set.
User Path.Combine to add your root and the user id:
var userPath = Path.Combine(uploadPath,userID)
This is the safest way to create what you need. The Directory.CreateDirectory method will create all the subfolders as needed:
var userPath = Path.Combine(uploadPath,userID)
if (Directory.Exists(Server.MapPath(userPath))) return;
else Directory.CreateDirectory(Server.MapPath(userPath));

Azure - How to access content files of WorkerRole?

I'm writing a worker role for sending emails. It has some email template html files with build action = content and copy to output = Copy Always
How can i access those files from the code of the WorkerRole?
I don't want to store those files in a blob because i need to upload this service as soon as possible and i have to be able to edit those email template easily without wiring up extra code for that.
EDIT:
Guys i'm talking about Azure. This doesn't work with the regular method of loading the Folder of the current running assembly because that would give you the Azure host process which is located in a different place.
I figured it out - here's how to do it:
Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + #"\", #"approot\FileTemplates\");
Having a build action - content does not embed the file into the .dll, it is deployed into your assembly directory (usually \bin), then in the same folder structure that you have the template in. That was confusing to write, so here is an example:
Project Directory
-Templates
-EmailTemplateA
When complied and deployed, EmailTemplateA would be in the following location: \bin\Templates\EmailTemplateA
Now that we know where it is at, we need to use it. Below is a code snippet that would load a template, replace some values and then send your email
public void SendRegistrationConfirmation(string toAddress, string confirmUrl)
{
const string subject = "Your Registration";
//load the template
var template = File.OpenText(AssemblyDirectory + " \\Templates\\NewProgramRegistration.Template").ReadToEnd();
//replace content in the template
//We have this #URL# string in the places we want to actually put the URL
var emailContent = template.Replace("#URL#", confirmUrl);
//Just a helper that actually sends the email, configures the server, etc
this.SendEmail(toAddress, subject, emailContent);
}
You could store your templates in Local Storage:
http://convective.wordpress.com/2009/05/09/local-storage-on-windows-azure/
You should reconsider you design.
- as mentioned above, you can use Local Storage (you would need to copy the files there first) and then you can use the System.IO .NET API to manipulate the files
The problem with this is (as you said you are making changes)
- what if you horizontally scale, now you have individual worker roles that have their own local copy of the "template". You mention not wanting to use blob storage, but that should be an option since it can act as a central/persisted repository for your templates. And you can copy them locally of course as needed.
Another option is to use SQL Azure DB. Something like templates, should be super fast on it that multiple roles can share.

Categories

Resources