Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Algorytm C# - Przykład 4: usunięcie załącznika

Podsumowanie:

Poniższy kod akcji C# usuwa wszystkie wersje załącznika o podanym identyfikatorze.

var baseUri = new System.Uri(TenantBaseUrl);
var _endpointUri = new System.Uri(baseUri, "publicapi/attachment/removeAttachment");
var _authUri = new System.Uri(baseUri, "connect/token");
var _userName = "tutaj nazwa użytkownika, który ma dostęp do public-api";
var _userPassword = "tutaj hasło użytkownika";
var _scope = "public-api";
var _clientSecret = "secret";
var _clientId = "openjs";

var attachmentId = 0; //<-- tutaj podajemy id załącznika, który chcemy usunąć
                       //poniższy kod usuwa załącznik o podanym id wraz ze wszystkimi wersjami

var request = new CSharpScript.WebServiceRunner.Models.RestRequestModel()
{
    Method = System.Net.Http.HttpMethod.Delete,
    Url = $"{_endpointUri.AbsoluteUri}?id={attachmentId}",
    AuthType = ApiConnector.Enums.AuthType.OAuth2Password,
    AuthUrl = _authUri.AbsoluteUri,
    UserName = _userName,
    Password = _userPassword,
    ClientId = _clientId,
    ClientSecret = _clientSecret,
    Scope = _scope,
};

var response = await CSharpScript.WebServiceRunner.RestManager.Instance.ExecuteRequestAsync(request);

if(!response.IsSuccess)
{     
    throw new System.Net.WebException(response.RawResult); 
}
|← Algorytm C# - Przykład 3: pobranie załącznika |↑ Do góry |→ Importowanie dokumentów |

Copyright © 2025 OPTEAM SA. Theme Copyright © 2017-2020 Patrick Marsceill. Distributed by an MIT license.