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"
};
Related
I'm currently building an ASP.NET Core 5 MVC for my course. I'm using Cloudinary for storing files in the cloud so I can get bonus points, but I have a problem with deleting files from it. In the documentation is written that I should use DeletionParams class and pass the publicId which I'm storing in the database, but whatever I do the DeletionParams class is returning me "not found".
public void DeleteFile(string publicId)
{
var deletionParams = new DeletionParams(publicId)
{
ResourceType = ResourceType.Raw
};
var results = cloudinary.Destroy(deletionParams);
;
}
And this is what parameters I pass to it
And this is the result from cloudinary
If more information is needed just ask in the comment section.
I found what was the problem. When you want to delete an image you should provide folder and publidId and also ResourceType = ResourceType.Image. If you want to delete a video it's the same way the only thing you should change is ResourceType to ResourceType.Video. For any kinds of other files you should provide full path plus public id and also the file extension and ResoureType should be ResourceType.Raw
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to copy a file into another folder, here is my code.
private static void CopyDirectory(DirectoryInfo source, DirectoryInfo target)
{
foreach (var sourceFilePath in Directory.GetFiles(source.FullName))
{
FileInfo file;
if(IsAccesable(sourceFilePath, out file))
{
file.CopyTo(target.FullName); //ERROR HERE
}
else
{
//DO WORKAROUND
}
}
foreach(var sourceSubDirectoryPath in Directory.GetDirectories(source.FullName))
{
DirectoryInfo directory;
if(IsAccesable(sourceSubDirectoryPath, out directory))
{
var targetSubDictionary = target.CreateSubdirectory(Path.Combine(target.FullName, sourceSubDirectoryPath));
CopyDirectory(directory, targetSubDictionary);
}
else
{
//DO WORKAROUND
}
}
}
I keep getting the error message: The target path "" is a directory and not a file
Full sourcePath:
"c:\\Hypixel Bots Interface\\.gitattributes"
Full targetPath:
"C:\\Users\\wout\\source\\repos\\FileCloner\\FileCloner\\bin\\Debug\\net5.0\\Target\\Hypixel Bots Interface"
There is no file in your path. For example, create a file in your folder and name it test.txt an run again your code to verify if the error will disappear.
"C:\Users\wout\source\repos\FileCloner\FileCloner\bin\Debug\net5.0\Target\Hypixel Bots Interface\.gitattributes\test.txt"
As the error says, you want the targetPath to be a file name. You are just pointing to a folder.
"C:\\Users\\wout\\source\\repos\\FileCloner\\FileCloner\\bin\\Debug\\net5.0\\Target\\Hypixel Bots Interface\\.gitattributes"
That would be pointing to a new file in that directory
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"
}
Question Background:
I have a WebApi controller who's logic code relies on reading data contained in a number of XML files. These XML files have been included in the App_Data folder of the WebApi project.
The Issue:
I'm trying to use the relative path of the XML files in the following way:
[System.Web.Http.HttpGet]
public string CallerOne()
{
string docOne = #"~\AppData\DocOne.xml";
string poll = #"~\AppData\Poll.xml";
var response = _Caller.CallService(docOne, poll);
return ConvertXmlToJson(response);
}
When running the WebApi code and calling the Url to the CallerOne method I receive the following error:
An exception of type 'System.IO.DirectoryNotFoundException'
occurred in System.Xml.dll but was not handled in user code
Additional information: Could not find a part of the path
'C:\Program Files (x86)\IIS Express\~\AppData\FPS.xml'.
I also want to eventually publish this to Azure and include these files.
How can I use the relative path to read in the XML files in the App_Data folder?
Ended up finding the answer.
The following is needed to read the relative paths in a WebApi project:
var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(#"~/App_Data/yourXmlFile.xml");
As jdweng inferred several months back, Environment.GetEnvironmentVariable("AppData") would seem to be the preferred method. The OP's auto-accepted answer and that give quite different results. For example, using both of those in my project, I get:
C:\\Projects\\PlatypusReports\\PlatypusReports\\App_Data\\yourXmlFile.xml
...for the OP's long-winded code, namely this:
var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(#"~/App_Data/yourXmlFile.xml");
...and this:
C:\\Users\\cshannon\\AppData\\Roaming
...for jdweng's code, to wit:
string appData = Environment.GetEnvironmentVariable("AppData");
OTOH, this code:
string appDataFolder = HttpContext.Current.Server.MapPath("~/App_Data/");
returns:
C:\\Projects\\PlatypusReports\\PlatypusReports\App_Data\
So it's very similar in results (if not methodology) to the first example above. I actually got it from a question I asked almost two years ago, which I had forgotten about.
I'm not positive if jdweng's approach would work as expected once the app is deployed on a server, but I have much more confidence in it than the other approaches.
Can anyone verify?
UPDATE
The accepted answer here has 237 upvotes at time of typing, so seems pretty reliable, albeit 6 years old (42 in dog years, which may be a good sign).
Your approach is fine. You just had some tpying error,
You wrote
string docOne = #"~\AppData\DocOne.xml";
But it should have been
string docOne = #"~\App_Data\DocOne.xml";
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.