In this bankruptcy, we will discover ways to replace the files. Using Azure portal, you can without difficulty replace report with the aid of commencing the report in Document explorer and updating it in editor like a text file.
Click ‘Save’ button. Now while you want to alternate a file using .Net SDK you may simply update it. You don't want to delete and recreate it, which except being tedious, would additionally change the aid identification, which you would not need to do while you're just modifying a document. Here are the following steps to update the file the use of .Net SDK.
Let’s test the subsequent ReplaceDocuments project wherein we will query for files wherein the isNew belongings is proper, however we are able to get none because there aren't any. So, let's modify the documents we brought in advance, the ones whose names start with New Customer.
Step 1 − Add the isNew assets to those files and set its value to true.
private async static Task ReplaceDocuments(DocumentClient client) {
Console.WriteLine();
Console.WriteLine(">>> Replace Documents <<<");
Console.WriteLine();
Console.WriteLine("Quering for documents with 'isNew' flag");
var sql = "SELECT * FROM c WHERE c.isNew = true";
var documents = client.CreateDocumentQuery(collection.SelfLink, sql).ToList();
Console.WriteLine("Documents with 'isNew' flag: {0} ", documents.Count);
Console.WriteLine();
Console.WriteLine("Quering for documents to be updated");
sql = "SELECT * FROM c WHERE STARTSWITH(c.name, 'New Customer') = true";
documents = client.CreateDocumentQuery(collection.SelfLink, sql).ToList();
Console.WriteLine("Found {0} documents to be updated", documents.Count);
foreach (var document in documents) {
document.isNew = true;
var result = await client.ReplaceDocumentAsync(document._self, document);
var updatedDocument = result.Resource;
Console.WriteLine("Updated document 'isNew' flag: {0}", updatedDocument.isNew);
}
Console.WriteLine();
Console.WriteLine("Quering for documents with 'isNew' flag");
sql = "SELECT * FROM c WHERE c.isNew = true";
documents = client.CreateDocumentQuery(collection.SelfLink, sql).ToList();
Console.WriteLine("Documents with 'isNew' flag: {0}: ", documents.Count);
Console.WriteLine();
}
Step 2 − Get the documents to be updated the use of the identical STARTSWITH query and that gives us the documents, which we are getting back here as dynamic items.
Step 3 − Attach the isNew property and set it to actual for each record.
Step 4 − Call ReplaceDocumentAsync, passing in the file's SelfLink, along with the up to date report.
Now simply to show that this worked, question for files wherein isNew equaled proper. Let’s name the above queries from the CreateDocumentClient venture.
private static async Task CreateDocumentClient() {
// Create a new instance of the DocumentClient
using (var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey)) {
database = client.CreateDatabaseQuery("SELECT * FROM c WHERE c.id =
'myfirstdb'").AsEnumerable().First();
collection = client.CreateDocumentCollectionQuery(database.CollectionsLink,
"SELECT * FROM c WHERE c.id = 'MyCollection'").AsEnumerable().First();
//await CreateDocuments(client);
//QueryDocumentsWithSql(client);
//await QueryDocumentsWithPaging(client);
//QueryDocumentsWithLinq(client);
await ReplaceDocuments(client);
}
}
When the above code is compiled and performed, you'll get hold of the subsequent output.
**** Replace Documents ****
Quering for documents with 'isNew' flag
Documents with 'isNew' flag: 0
Quering for documents to be updated
Found 2 documents to be updated
Updated document ‘isNew’ flag: True
Updated document ‘isNew’ flag: True
Quering for documents with 'isNew' flag
Documents with 'isNew' flag: 2