MS GraphAPI Drives Create new folder - c#

I need help with Microsoft GraphAPI.
I want to create folder in SharePoint Online Site Collection, in Document Library, but i get Error.
I Have Site Collection, name A,
in this Site Collection i have Document Library, name XY
I have tried to create Folder using this
POST /sites/{site-id}/drive/items/{parent-item-id}/children
https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online
But i always get error, 400 Bad Request.
.../v1.0/sites/tenantName,1a2b3f27-0d23-4b68-8e71-fe06cbfed6b4,5e911195-1934-42a3-814c-86ab8ec2699c/drive/items/b!Jz8rGiMNaEuOcf4Gy_7WtJURkV40GaNCgUyGq47CaZwdNH0_zurqQ6XWJreCPMnF/children";
Error message is, "The expression is not valid".
What am I doing wrong?

It seems that you are using driveId as the parent-item-id. The parent-item-id looks like 01KC572RLYVJZL5JE4ANCLOTQKQMIKYVHL
You can get the parent-item-id by using
GET /sites/{site-id}/drive/root/children
If you get nothing from this request, you should create a folder under the root directory first.
POST /sites/{site-id}/drive/root/children
{
"name": "New Folder222",
"folder": { },
"#microsoft.graph.conflictBehavior": "rename"
}

Related

iOS iCloud failing to write with, Couldn't get container configuration from the server error

I have one app that I wrote already reading from and writing to the iCloud. I am essentially using the same code in my new app to do the same thing, but for some reason it will not work, giving me the following error, "Couldn't get container configuration from the server". Let me clarify, with this new app it does puts an entry in iCloud under manage storage, but instead of being under the name of my app, it is under adhoc.
Here is the line in my info.Plist,
Here is the line from my Entitlements,plist
lastly, here is my identifier defined on the apple developer site,
I have verified and reverified that everything is pointing to the correct thing so I am baffled. Any help would be much appreciated.
EDIT I guess what it is doing is writing file to my phone, but when it goes to save data to it, it fails with this message, Here is my call to save the data.
CKRecordID recordID = new CKRecordID(strDate);
await Task.Delay(200);
// Save it to iCloud
await pvc.SaveToiCloud(newRecord);
Here is my code to save the record,
public async Task SaveToiCloud(CKRecord newRecord)
{
ThisApp.PrivateDatabase.SaveRecord(newRecord, (record, err) =>
{
Edit:
I was thinking that possibly the number of nodes I had was too many, so I took out the "dist" one you see below, but that did not help. I thought maybe that was why I was seeing module name of adhoc under icloud on my phone, but I guess I was wrong.
Old:
New:
Edit
I have been doing more digging and found that this line of code is actually the one throwing the error.
File.WriteAllText(Path.Combine(filePath.Path, name + date), "Test");
The name and date contain correct values and the path looks fine to me... I guess... Don't know actually how it should look. Here is how the file path is getting set right above this call,
NSUrl filePath = NSFileManager.DefaultManager.GetUrlForUbiquityContainer(null).Append("Documents", true);
If anyone could offer any advice, I would be most appreciative.
So, I finally figured out the issue and it works like a champ now. The issue was the case in my bundle id in my info.plist. In CloudKit the DB name was all lower case, but my bundle Id in my info.plist, had AdHoc as my last node instead of adhoc as was in the CloudKit. You might say, what does the bundle Id have to do with the iCloud name, and actually I am not really sure, but I noticed that it was taking the case of that last node from my Bundle Id, not the case specified in the iCloud definition as I have shown above. Hope this helps someone who is struggling with a similar issue Have a great day!

OpenApi (Redoc) remote (network) nested references

We have a running Redoc server, which includes a bunch on yaml files with api specifications. However, a couple of neccesary yaml files are not on the local (let's call it RedocServer) machine.
Those remote files are accessible through aspnet-webapi service (WebApiServer).
So, let's say, to get one of those files, we use refernce in the index.yaml file:
paths:
/api/1:
$ref: "https:/some-address/ApiDoc.yaml"
If ApiDoc.yaml itself has no refences, there is no problem for WebApiServer to simply return a string using a method like that:
[HttpGet]
public string GetApiDoc()
{
var directoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = Path.Combine(directoryPath, "ApiDoc.yaml");
return File.ReadAllText(filePath);
}
However, in our case, that ApiDoc.yaml has some huge, nested references to another files inside it. Something like that, implying that referenced objects have references inside them:
post:
tags:
- Test
summary: Test
operationId: Test
consumes:
- application/json
produces:
- application/json
requestBody:
content:
application/json:
schema:
$ref: "../ApiDoc2.yaml#/components/schemas/ApiRequest"
responses:
200:
description: OK
content:
application/json:
schema:
$ref: "../ApiDoc3.yaml#/components/schemas/ApiResponse"
If WebApiServer returns a string like that, RedocServer will probably just try to resolve these references with RedocServer files. But we obviously want to make sure that refernces will be resolved on the WebApiServer side.
So, the question is, how to properly return that ApiDoc.yaml without breaking any references?
We cannot resolve references manually because objects are huge and deeply nested. OpenApi.net, which we tried to use, still isn't able to resolve remote references automatically, and also doesnt't seem to be able to work with files without "info" and "openapi:3.0.0" part in it.
As it turns out, Redoc automatically parses remote references, replacing local path in urls with remote url.
So simply put: you can just return a string or file like that, and everything should be working all right.

Cannot create a folder in a list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to create a folder in a list, the following does not work:
var folder = new DriveItem
{
Name = plan.Title,
Folder = new Folder()
};
await graphServiceClient
.Sites["ourdomain.sharepoint.com:/sites/ITOddeleni:"]
.Lists["Planner"]
.Drive
.Root
.Children
.Request()
.AddAsync(folder);
I am using these as parameters for other calls, can I leave it be or does it expect GUID?
EDIT 1
The ERROR quote is Code:
BadRequest
Message: Url specified is invalid.
So I assume the .Sites and .Lists should have GUID but after replacing the Site URL with Id of site and ID of the list I get the following:
Code: -1, Microsoft.SharePoint.Client.ResourceNotFoundException
Message: Cannot find resource for the request Microsoft.FileServices.FileService/Sites('50cb05fa-27f9-45bf-a5f3-5f82e0e2eb00')/lists('ad52e785-c9b7-4106-af7b-a3394462875c')/drive/.
EDIT 2
I have tried to create the folder via Graph Explorer, found the content type ID for the folder on a list and used POST https://graph.microsoft.com/v1.0/sites/50cb05fa-27f9-45bf-a5f3-5f82e0e2eb00/lists/ad52e785-c9b7-4106-af7b-a3394462875c/items
With this Request body
{
"Title" : "Test2",
"contentType": { "id": "0x012000FC4989A03C9F7845AD8C206E2F47A0FD" }
}
Now the folder gets created, but the call requires Title, but does not accept Name, which results in created folder without Name (title). Edit: It does accept "name"with lowercase N, but still the name is not shown in the list. Tried to send it as "BaseName", "FileLeafRef" and some other internal names of Folder, but without success.
Without an error message, it isn't clear exactly what is happening here. That said, the syntax for creating a new folder should look like this:
var folder = new DriveItem
{
Name = plan.Title,
Folder = new Folder { },
#microsoft.graph.conflictBehavior = "rename"
};

TFS ServerItemExists method of versionControlServer returns file not exists, while it is present

I'm trying to update in-house developed plugin for Azure DevOps Server. Previously company was using TFS 2017, and plugin worked correctly. Now, it launches (I see it through messages in EventLog), but there is an issue, that function ServerItemExists returns "False", but actually file is present.
I have found issues about that versionControl TfsConfigurationServer.GetService() always returns null
(TfsConfigurationServer.GetService<VersionControlServer>() always returns null), but it seems to be not my case. Here code below
var configFileServerPath = $"$/{projectName}/AutoCodeReview.xml";
var versionControlServer = projectCollection.GetService<VersionControlServer>();
writeLog(EventLogEntryType.Information, $"Details. configFileServerPath: {configFileServerPath}. versionControlServer.TeamProjectCollection.Name: {versionControlServer.TeamProjectCollection.Name}");
bool ItemExists = versionControlServer.ServerItemExists(configFileServerPath, ItemType.File);
writeLog(EventLogEntryType.Information, $"Item existence: {ItemExists}");
if (!ItemExists)
{
writeLog(EventLogEntryType.Information, $"return, not item exists");
return null;
}
So I use EventViewer as smth like debug output, and I see, that I've got message as "Item existence false". But file exists!
My suggestions in path defining.
URL in browser to element looks like this: http://tfs1:8080/tfs/DefaultCollection/Project1/_versionControl?path=%24%2FProject1%2FAutoCodeReview.xml
As I figure out by EventVwr, these are paths:
configFileServerPath $/Project1/AutoCodeReview.xml
TeamProjectCollection.Name http://tfs1:8080/tfs/DefaultCollection/
So this works fine in TFS 2017, and shows that there is no file in Azure DevOps Server 2019. As I new to C#, it seems to be difficult to realize what is wrong.

Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Index'

I know this question was asked month before but was never answered.
My program starts normally but after returning View["Index", blogPost] it could not find the Index.cshtml and raises an exception.
Get["/"] = parameters =>
{
var blogPost = new BlogPost
{
Id = 1,
Title = "Test",
Content = "Lorem ipsum...",
Tags = { "c#", "aspnetmvc", "nancy" }
};
return View["Index", blogPost];
};
Exception:
Nancy.RequestExecutionException: Oh noes! ---> Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Index'
Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
Locations inspected: views/Home/Index-de-DE,views/Home/Index,Home/Index-de-DE,Home/Index,views/Index-de-DE,views/Index,Index-de-DE,Index`
If the answer giving my Christian doesn't help you like it didn't help me there is a alternative issue/solution. The alternative is to make sure that the file you created is being copied to the output directory at compile time. You can check it under the properties tab like shown bellow
The exception message tells you where Nancy tried to look for the view:
Locations inspected: views/Home/Index-de-DE,views/Home/Index,Home/Index-de-DE,Home/Index,views/Index-de-DE,views/Index,Index-de-DE,Index
The exception also tells you which file extensions Nancy tried to look for:
Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
That is Nancy looks for a file in one of the listed locations with one of the listed extensions.
So the question is if your index.cshtml is in one the listed folders. If not you can either move it there or set up a view location convention.
We ran into this error and noticed the .cshtml file it was complaining about was not getting copied to the server. The solution was in Visual Studio, in the file's properties, we changed the Build Action to Content. This forces it to get included in the build artifacts that are deployed to the server. Similarly you could change the Copy to Output Directory to Always as others have mentioned; either works, but I find setting the file as Content a bit more informative.
In your case, I'm guessing you have an Index.cshtml file which you need to set this property on.

Categories

Resources