C# Archives -

Tag Archives: C#

Migrating Data from Azure Files Share to Azure Blob Storage Using C#

For growing businesses, efficient data management is as critical as streamlined processes and actionable reporting. As organizations scale, the volume and complexity of data stored in systems like Azure Files Share increase, necessitating robust, scalable storage solutions like Azure Blob Storage. Are you struggling to manage your file storage efficiently? If you’re looking to automate data migration from Azure Files Share to Azure Blob Storage using C#, this article is for you. Research shows that 70% of customers value seamless experiences with efficient systems, impacting brand loyalty. Businesses automating data management processes can reduce retrieval times by up to 90%, while organizations leveraging cloud storage solutions like Azure Blob Storage report a 25% increase in operational productivity and 60% improved satisfaction in data workflows. This article provides a structured guide to migrating data using C#, drawing from practical implementation insights to help Team Leads, CTOs, and CEOs optimize their data storage for scalability and efficiency. Why Migrate to Azure Blob Storage? Azure Files Share offers managed file shares via the Server Message Block (SMB) protocol, suitable for traditional file system needs. However, Azure Blob Storage excels in scalability, cost efficiency, and integration with advanced Azure services like Azure Data Lake and AI/ML workloads. Key benefits include: Migrating Data Using C#: A Step-by-Step Approach To migrate data from Azure Files Share to Azure Blob Storage programmatically, you can leverage C# with Azure SDKs. Below is a structured approach, referencing a C# implementation that uses a timer-triggered Azure Function to automate the process. Step 1: Set Up Your Environment Step 2: Design the Migration Logic The C# code uses an Azure Function triggered on a schedule (e.g., every 5 seconds) to process files. Key components include: Step 3: Execute the Migration Step 4: Optimize and Automate Step 5: Validate and Test A Glimpse of the C# Implementation The C# code leverages an Azure Function to automate migration. It connects to the file share, enumerates files, uploads them to a blob container, and deletes them from the source upon successful transfer. Key features include: This approach ensures minimal manual intervention and robust error handling, aligning with the needs of growing businesses. Benefits of Programmatic Migration Using C# for migration offers: To conclude, migrating data from Azure File Share to Azure Blob Storage using C# empowers growing businesses to achieve scalable, cost-efficient, and automated data management. By implementing a structured approach with Azure Functions, you can streamline operations and unlock advanced analytics capabilities. Evaluate your current data management processes and identify one area for improvement, such as automating file transfers with C#. Start today to enhance efficiency and customer satisfaction. We hope you found this blog useful, and if you would like to discuss anything, you can reach out to us at transform@cloudfonts.com.

Automating File Transfers from Azure File Share to Blob Storage with a Function App

Efficient file management is essential for businesses leveraging Azure cloud storage. Automating file transfers between Azure File Share and Azure Blob Storage enhances scalability, reduces manual intervention, and ensures data availability. This blog provides a step-by-step guide to setting up an Azure Timer Trigger Function App to automate the transfer process. Why Automate File Transfers? Steps to Implement the Solution 1. Prerequisites To follow this guide, ensure you have: 2. Create a Timer Trigger Function App 3. Install Required Packages For C#: For Python: 4. Implement the File Transfer Logic C# Implementation 5. Deploy and Monitor the Function To conclude, automating file transfers from Azure File Share to Blob Storage using a Timer Trigger Function streamlines operations and enhances reliability. Implementing this solution optimizes file management, improves cost efficiency, and ensures compliance with best practices. Begin automating your file transfers today! Need expert assistance? Reach out for tailored Azure solutions to enhance your workflow. We hope you found this blog useful, and if you would like to discuss anything, you can reach out to us at transform@cloudfonts.com.

Inheritance in C#

Posted On February 15, 2023 by Sourav Patil Posted in Tagged in ,

In C#, inheritance is a way to create a new class that is a modified version of an existing class. The new class is called the derived class, and the existing class is the base class. The derived class inherits the base class members, which means it has access to all of the base class’s fields and methods. This is useful because it allows you to reuse code and avoid writing the same code over again in the derived class. To create a derived class in C#, you use the: operator, followed by the name of the base class. For example: The derived class can then use the base class members as if they were it’s own. It can also override the base class’s methods or hide them with the new keyword. In the example above, the derived class is overriding the Some Method method from the base class, which means that it is providing a new implementation for that method. The new keyword is used to hide the Some Other Method method from the base class, which means that the derived class provides its own version of the method that is separate from the one in the base class. In addition to inheriting from a single base class, a class in C# can also implement one or more interfaces. An interface is a set of related methods that a class can implement. A class that implements an interface must provide an implementation for each of the methods in the interface. In the example above, the derived class is both derived from the Base Class and implements the Isom Interface. This means that it has access to all of the members of the Base Class as well as the method defined in the Isom Interface. In C#, inheritance is a powerful tool that allows you to create new classes based on existing ones. It helps you reuse code and avoid having to write the same code over again, saving time and making your code easier to maintain.

Use of Environment Variable inside Azure Function in C#

In this blog, we will learn how to configure and use Environment Variable in Azure Function. Concept of using Environment variable during your development which needs to deploy on multiple servers and connect to multiple systems. Whenever you use Environment variables to store the global constant or system credentials it reduces the time which was required to modify the code base for multiple deployments. Let’s get started with Creating the Azure Function and using the Environment variable. Step 1: Create an Azure Function inside the Visual Studio: I have created the HTTP Trigger Azure function inside Visual Studio and the authorization level is Anonymous Once you create an Azure Function project you will notice there are many files created with the project.  We have a “local.setting.json” file that we are going to use and it holds the environment variable while the development and testing phase of your Azure function. Step 2: Declare credentials/global variable inside “local.setting.json” Information on local.setting.json – This file represents your local application setting for your Azure Function and it stays with your local build only. While you publish your azure function to Azure Portal or commit your code to your Repo this file is never pushed to the server as they are excluded/prevent from committing or publishing. Step 3: Access variable inside the code You can access the environment variable using the Environment class(required System lib). Based on your preference you can either access Environment variable the directly inside the code or you can create a CONSTANT class as mentioned below screenshot. Here, I am passing this environment variable inside a response so that we can test it. Step 4: Testing using Postman We will require the API testing tool, here I am using Postman and the following is the link to download “Postman”. https://www.postman.com/downloads/ To test the application, click on the Start button on top of the Navbar as mentioned below in the screenshot [Button will have Project Name]. It will take a few minutes to Load the Azure Emulator Following is the screen you will be able to see and copy the URL highlighted in the red below and paste that URL into Postman. Result: Now, you need to configure the Environment while deploying the Azure function on Azure Portal, and below are steps for the same: Step 1: Deploy an Azure Function on Azure Portal. You can directly create it on Portal or you can create it from Visual Studio. Here I am going to create and deploy it from Visual Studio: Right Click on the project and select Publish: Select Azure and Click on Next: Click on the + icon to create a new function, You can use the existing resource group or create a new resource group as per your preference: After deployment is completed you can see the deployed Azure function on Azure Portal: Now, if you try to use the Azure Function URL and post the request then you will notice that all the environmental credentials part is missing as we have not configured the environment variable on the Azure portal inside Azure Function App: Step 2: Configure the App Environment variable on Azure Portal for online deployment. Navigate to the Configuration section of your deployed Azure Function Add the Application setting in your Configuration and the Name should same as you have declared in your local.setting.json file. Make sure your click on Save to update the configuration on Portal. After configuration if you test your deployed Azure function using postman you will get your expected result: This is how you can configure and use the Environment variable inside your Azure Function. It will make your life easier while deploying Azure on Development, UAT, or Production Environment. You can store the Source and Destination system credentials, SQL Access credentials, or Custom Global Variable based on your business requirement of integration.

Serializing and Deserializing Json objects with key value pairs in C#

Posted On March 30, 2022 by Shruti Gupta Posted in Tagged in ,

If we have a json data whose objects have one or more key value pairs also known as properties and we need to separate them into individual objects then Serializing and Deserializing method can be used in C#. Sample Json data :      {                                 “FirstName”:”Aditya”,                                 “MiddleName”:”Ashok”,                                 “LastName”:”Somwanshi”,                                 “Phone”:[“9004802526″,”34304235”],                                 “Address”:{“Primary”:”Panvel”, “Secondary”:”Cloudfronts”}                             } Desired Output: {   “FullName”: “Aditya Ashok Somwanshi”,   “Primary Phone”: “9004802526”,   “Secondary Phone”: “34304235”,   “Primary Address”: “Panvel”,   “Secondary Address”: “Cloudfronts” } First open Visual Studio and create new project in Console application template. Give your Project a name and click next, you will be directed to a new page where you can start with your code. Now we need to install some packages into our project to use it in our code. So at top in the tools section select NuGet Package Manager and in that select Manage Nuget Packages for Solution Now search for Newtonsoft.Json and install the package The purpose for installing this package is to access serialize and deserialize functions in our code. To add a class to main program you need to right click on your project and then select and choose add new item Select class and name the class and add. Now to write the code we need to use Convert JSON to C# Classes Online – Json2CSharp Toolkit for formatting the json to C# and knowing the classes to be used. using System.Collections.Generic; using Newtonsoft.Json; namespace Human {     public class Address     {         public string Primary { get; set; }         public string Secondary { get; set; }     }     public class Person     {         public string FirstName { get; set; }         public string MiddleName { get; set; }         public string LastName { get; set; }         public List<string> Phone { get; set; }         public Address Address { get; set; }     }     public class Root     {         public string FullName { get; set; }         [JsonProperty(“Primary Phone”)]         public string PrimaryPhone { get; set; }         [JsonProperty(“Secondary Phone”)]         public string SecondaryPhone { get; set; }         [JsonProperty(“Primary Address”)]         public string PrimaryAddress { get; set; }         [JsonProperty(“Secondary Address”)]         public string SecondaryAddress { get; set; }     } } Now the main program using Newtonsoft.Json; using System; namespace Human {     public class Program     {         public static void Main(string[] args)         {             string json = @”{                                 “”FirstName””:””Aditya””,                                 “”MiddleName””:””Ashok””,                                 “”LastName””:””Somwanshi””,                                 “”Phone””:[“”9004802526″”,””34304235″”],                                 “”Address””:{“”Primary””:””Panvel””, “”Secondary””:””Cloudfronts””}                             }”;//Defining Json             Person human = JsonConvert.DeserializeObject<Person>(json);//Deserializing Json             Root rt = new Root();             rt.FullName = human.FirstName + ” ” + human.MiddleName + ” ” + human.LastName;  //Concatenating Names             rt.PrimaryPhone = human.Phone[0];             rt.SecondaryPhone = human.Phone[1];             rt.PrimaryAddress = human.Address.Primary;             rt.SecondaryAddress = human.Address.Secondary;             string output = JsonConvert.SerializeObject(rt, Formatting.Indented);//Serializing Json             Console.WriteLine(output);         }     } } OUTPUT:

SEARCH :

FOLLOW CLOUDFRONTS BLOG :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange