All Products
Search
Document Center

.NET SDK

Last Updated: Apr 28, 2019

Preparations

  1. Before installing and using Alibaba Cloud SDKs, make sure that you have registered an Alibaba Cloud account and generated an AccessKey. For more information, see Create an AccessKey.

  2. Install the .NET SDK.

    • (Recommended) Install the SDK by using the dependency tool.
      You can use the NuGet package manager to install the .NET SDK. In the Solution Explorer panel, right-click your project and select Manage NuGet Packages from the drop-down menu. In the NuGet panel that appears, click the Browser tab, enter aliyun-net-sdk-core in the search bar, and then click Install. You can also use .NET CLI tools to install the SDK.

      1. dotnet add package aliyun-net-sdk-core
    • Download and install the SDK on your own.
      You can run the git clone command or use other methods to download aliyun-net-sdk-core and add a solution as required. To download aliyun-net-sdk-core in GitHub, visit aliyun-net-sdk-core.
  3. Install the Image Search .NET SDK.

    • (Recommended) Install the SDK by using the dependency tool.
      You can use the NuGet package manager to install the .NET SDK. In the Solution Explorer panel, right-click your project and select Manage NuGet Packages from the drop-down menu. In the NuGet panel that appears, click the Browser tab, enter aliyun-net-sdk-imagesearch in the search bar, and then click Install. You can also use .NET CLI tools to install the SDK.

      1. dotnet add package aliyun-net-sdk-imagesearch
    • Download and install the SDK on your own.
      You can run the git clone command or use other methods to download aliyun-net-sdk-imagesearch and add a solution as required. To download aliyun-net-sdk-imagesearch in GitHub, visit aliyun-net-sdk-imagesearch.

Sample code

  1. using System;
  2. using System.IO;
  3. using Aliyun.Acs.Core;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.ImageSearch.Model.V20190325;
  6. namespace Test
  7. {
  8. class Demo
  9. {
  10. static void Main(string[] args)
  11. {
  12. IClientProfile profile = DefaultProfile.GetProfile("<region>", "<your-access-key-id>", "<your-access-key-secret>");
  13. DefaultProfile.AddEndpoint("<region>", "<region>", "ImageSearch", "imagesearch.<region>aliyuncs.com");
  14. IAcsClient client = new DefaultAcsClient(profile);
  15. // Add an image.
  16. AddImageRequest addRequest = new AddImageRequest();
  17. addRequest.InstanceName = "demo";
  18. addRequest.ProductId = "test";
  19. addRequest.PicName = "test";
  20. byte[] img = System.IO.File.ReadAllBytes("c:/demo.jpg");
  21. string pic = Convert.ToBase64String(img);
  22. addRequest.PicContent = pic;
  23. AddImageResponse addResponse = client.GetAcsResponse(addRequest);
  24. Console.WriteLine(addResponse.RequestId);
  25. //Search for an image.
  26. SearchImageRequest searchRequest = new SearchImageRequest();
  27. searchRequest.InstanceName = "demo";
  28. searchRequest.Type = "searchByName";
  29. searchRequest.ProductId = "test";
  30. searchRequest.PicName = "test";
  31. SearchImageResponse searchResponse = client.GetAcsResponse(searchRequest);
  32. Console.WriteLine(searchResponse.RequestId);
  33. // Delete an image.
  34. DeleteImageRequest request = new DeleteImageRequest();
  35. deleteRequest.InstanceName = "demo";
  36. deleteRequest.ProductId = "test";
  37. DeleteImageResponse deleteResponse = client.GetAcsResponse(deleteRequest);
  38. Console.WriteLine(deleteResponse.RequestId);
  39. }
  40. }
  41. }