Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 273c739

Browse files
committed
Fix issues with creating folders and uploading
1 parent a0e63d4 commit 273c739

7 files changed

Lines changed: 45 additions & 50 deletions

File tree

Api/API.csproj

Lines changed: 0 additions & 45 deletions
This file was deleted.

Api/Entities/OneDriveCreateFolder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
namespace KoenZomers.OneDrive.Api.Entities
44
{
5-
internal class OneDriveCreateFolder : OneDriveItemBase
5+
public class OneDriveCreateFolder : OneDriveItemBase
66
{
77
[JsonPropertyName("name")]
88
public string Name { get; set; }
99

1010
[JsonPropertyName("folder")]
1111
public object Folder { get; set; }
12+
13+
[JsonPropertyName("@microsoft.graph.conflictBehavior")]
14+
public string ConflictBehavior { get; set; } = "rename";
1215
}
1316
}

Api/Entities/OneDriveItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class OneDriveItem : OneDriveItemBase
129129
/// <summary>
130130
/// The conflict resolution behavior for actions that create a new item. An item will never be returned with this annotation. Write-only.
131131
/// </summary>
132-
[JsonPropertyName("@name.conflictBehavior")]
132+
[JsonPropertyName("@microsoft.graph.conflictBehavior")]
133133
public NameConflictBehavior? NameConflictBehahiorAnnotation { get; set; }
134134

135135
/// <summary>

Api/Entities/OneDriveUploadSessionItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace KoenZomers.OneDrive.Api.Entities
55
{
66
internal class OneDriveUploadSessionItem
77
{
8-
[JsonPropertyName("@name.conflictBehavior")]
8+
[JsonPropertyName("@microsoft.graph.conflictBehavior")]
99
public NameConflictBehavior FilenameConflictBehavior { get; set; }
1010

1111
[JsonPropertyName("name")]

Api/KoenZomers.OneDrive.Api.snk

-596 Bytes
Binary file not shown.

Api/OneDrive.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net9.0</TargetFrameworks>
5+
<AssemblyName>KoenZomers.OneDrive.Api</AssemblyName>
6+
<Version>2.5.0.0</Version>
7+
<Authors>Koen Zomers</Authors>
8+
<Company>Koen Zomers</Company>
9+
<Description>API in .NET 9.0 to communicate with OneDrive Personal and OneDrive for Business</Description>
10+
<PackageProjectUrl>https://github.com/ispysoftware/OneDriveAPI</PackageProjectUrl>
11+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
12+
<PackageReleaseNotes>- Recompiled to support .NET Framework 9.0</PackageReleaseNotes>
13+
<PackageLicenseUrl>https://github.com/KoenZomers/OneDriveAPI/blob/master/LICENSE.md</PackageLicenseUrl>
14+
<Copyright>Koen Zomers</Copyright>
15+
<RootNamespace>KoenZomers.OneDrive.Api</RootNamespace>
16+
<AssemblyVersion>2.5.0.0</AssemblyVersion>
17+
<FileVersion>2.5.0.0</FileVersion>
18+
</PropertyGroup>
19+
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
21+
<DocumentationFile>KoenZomers.OneDrive.Api.xml</DocumentationFile>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
25+
<DocumentationFile>KoenZomers.OneDrive.Api.xml</DocumentationFile>
26+
</PropertyGroup>
27+
28+
</Project>

Api/OneDriveApi.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,8 @@ protected virtual async Task<OneDriveItem> UploadFileViaResumableUploadInternal(
16201620
// Trigger event
16211621
UploadProgressChanged?.Invoke(this, new OneDriveUploadProgressChangedEventArgs(totalBytesSent, fileStream.Length));
16221622
break;
1623-
1623+
case HttpStatusCode.Unauthorized:
1624+
throw new ApplicationException("unauthorized");
16241625
// All fragments have been received, the file did already exist and has been overwritten
16251626
case HttpStatusCode.OK:
16261627
// All fragments have been received, the file has been created
@@ -1913,7 +1914,15 @@ protected virtual async Task<bool> RenameItemInternal(OneDriveItem oneDriveSourc
19131914
/// <returns>Typed OneDrive entity with the result from the webservice</returns>
19141915
protected virtual async Task<T> SendMessageReturnOneDriveItem<T>(OneDriveItemBase oneDriveItem, HttpMethod httpMethod, string url, HttpStatusCode? expectedHttpStatusCode = null) where T : OneDriveItemBase
19151916
{
1916-
var bodyText = oneDriveItem != null ? JsonSerializer.Serialize(oneDriveItem) : null;
1917+
var options = new JsonSerializerOptions
1918+
{
1919+
WriteIndented = true,
1920+
// Add the JsonStringEnumConverter
1921+
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
1922+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
1923+
};
1924+
1925+
var bodyText = oneDriveItem != null ? JsonSerializer.Serialize(oneDriveItem, oneDriveItem.GetType(), options) : null;
19171926

19181927
return await SendMessageReturnOneDriveItem<T>(bodyText, httpMethod, url, expectedHttpStatusCode);
19191928
}

0 commit comments

Comments
 (0)