Note:
This documentation is for version 4.19.0 of the library.
Some samples may not work with other versions.
Installation
Install the Google.Cloud.Dlp.V2 package from NuGet. Add it to
your project in the normal way (for example by right-clicking on the
project in Visual Studio and choosing "Manage NuGet Packages...").
Authentication
When running on Google Cloud, no action needs to be taken to authenticate.
Otherwise, the simplest way of authenticating your API calls is to
set up Application Default Credentials.
The credentials will automatically be used to authenticate. See
Set up Application Default Credentials for more details.
Create a client instance by calling the static Create or CreateAsync methods. Alternatively,
use the builder class associated with each client class (e.g. DlpServiceClientBuilder for DlpServiceClient)
as an easy way of specifying custom credentials, settings, or a custom endpoint. Clients are thread-safe,
and we recommend using a single instance across your entire application unless you have a particular need
to configure multiple client objects separately.
Using the REST (HTTP/1.1) transport
This library defaults to performing RPCs using gRPC using the binary Protocol Buffer wire format.
However, it also supports HTTP/1.1 and JSON, for situations where gRPC doesn't work as desired. (This is typically due to an incompatible proxy
or other network issue.) To create a client using HTTP/1.1, specify a RestGrpcAdapter reference for the GrpcAdapter property in the client builder.
Sample code:
var client = new DlpServiceClientBuilder
{
GrpcAdapter = RestGrpcAdapter.Default
}.Build();
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eThis webpage provides documentation for the \u003ccode\u003eGoogle.Cloud.Dlp.V2\u003c/code\u003e .NET client library, which is used for interacting with the Google Cloud Data Loss Prevention API.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the library is 4.16.0, and the page also lists links to documentation for previous versions, dating as far back as version 2.15.0.\u003c/p\u003e\n"],["\u003cp\u003eThe library defaults to using gRPC and Protocol Buffers for RPCs, but it can also be configured to use HTTP/1.1 and JSON instead.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation emphasizes the ease of authentication on Google Cloud, and it also provides information on how to use Application Default Credentials for other environments.\u003c/p\u003e\n"],["\u003cp\u003eThe page demonstrates a simple usage example of how to redact sensitive information in text using \u003ccode\u003eDlpServiceClient.Create();\u003c/code\u003e and \u003ccode\u003eDeidentifyContent()\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["Version latestkeyboard_arrow_down\n\n- [4.19.0 (latest)](/dotnet/docs/reference/Google.Cloud.Dlp.V2/latest)\n- [4.18.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.18.0)\n- [4.17.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.17.0)\n- [4.16.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.16.0)\n- [4.15.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.15.0)\n- [4.14.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.14.0)\n- [4.13.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.13.0)\n- [4.12.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.12.0)\n- [4.11.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.11.0)\n- [4.10.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.10.0)\n- [4.9.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.9.0)\n- [4.8.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.8.0)\n- [4.7.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.7.0)\n- [4.6.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.6.0)\n- [4.5.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.5.0)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.4.0)\n- [4.3.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.3.0)\n- [4.2.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.2.0)\n- [4.1.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.1.0)\n- [4.0.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/4.0.0)\n- [3.5.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/3.5.0)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/3.4.0)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/3.3.0)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/3.2.0)\n- [2.16.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/2.16.0)\n- [2.15.0](/dotnet/docs/reference/Google.Cloud.Dlp.V2/2.15.0) \n\nGoogle.Cloud.Dlp.V2\n===================\n\n`Google.Cloud.Dlp.V2` is a.NET client library for the [Google Cloud Data Loss Prevention API](https://cloud.google.com/dlp/).\n\nNote:\nThis documentation is for version `4.19.0` of the library.\nSome samples may not work with other versions.\n\nInstallation\n------------\n\nInstall the `Google.Cloud.Dlp.V2` package from NuGet. Add it to\nyour project in the normal way (for example by right-clicking on the\nproject in Visual Studio and choosing \"Manage NuGet Packages...\").\n\nAuthentication\n--------------\n\nWhen running on Google Cloud, no action needs to be taken to authenticate.\n\nOtherwise, the simplest way of authenticating your API calls is to\nset up Application Default Credentials.\nThe credentials will automatically be used to authenticate. See\n[Set up Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) for more details.\n\nGetting started\n---------------\n\nAll operations are performed through [DlpServiceClient](/dotnet/docs/reference/Google.Cloud.Dlp.V2/latest/Google.Cloud.Dlp.V2.DlpServiceClient).\n\nCreate a client instance by calling the static `Create` or `CreateAsync` methods. Alternatively,\nuse the builder class associated with each client class (e.g. DlpServiceClientBuilder for DlpServiceClient)\nas an easy way of specifying custom credentials, settings, or a custom endpoint. Clients are thread-safe,\nand we recommend using a single instance across your entire application unless you have a particular need\nto configure multiple client objects separately.\n\n### Using the REST (HTTP/1.1) transport\n\nThis library defaults to performing RPCs using [gRPC](https://grpc.io/) using the binary [Protocol Buffer](https://protobuf.dev) wire format.\nHowever, it also supports HTTP/1.1 and JSON, for situations where gRPC doesn't work as desired. (This is typically due to an incompatible proxy\nor other network issue.) To create a client using HTTP/1.1, specify a `RestGrpcAdapter` reference for the `GrpcAdapter` property in the client builder.\nSample code: \n\n var client = new DlpServiceClientBuilder\n {\n GrpcAdapter = RestGrpcAdapter.Default\n }.Build();\n\nFor more details, see the [transport selection](https://cloud.google.com/dotnet/docs/reference/help/transports) page.\n\nSample code\n-----------\n\nRedact information in plain text\n--------------------------------\n\n DlpServiceClient client = DlpServiceClient.Create();\n DeidentifyContentRequest request = new DeidentifyContentRequest\n {\n ParentAsProjectName = new ProjectName(projectId),\n Item = new ContentItem\n {\n Value = \"Hi! My phone number is 555-1234-567. Please call me!\"\n },\n DeidentifyConfig = new DeidentifyConfig\n {\n InfoTypeTransformations = new InfoTypeTransformations\n {\n Transformations =\n {\n new InfoTypeTransformation\n {\n PrimitiveTransformation = new PrimitiveTransformation\n {\n ReplaceConfig = new ReplaceValueConfig\n {\n NewValue = new Value { StringValue = \"(Redacted)\" }\n }\n }\n }\n }\n }\n }\n };\n DeidentifyContentResponse response = client.DeidentifyContent(request);\n Console.WriteLine(response.Item.Value);"]]