Posts

How to Preview the image and download which is in base64string format in mvc view using C#

  <div class="col-lg-9 col-xl-6">                                                     @if (reclaimdetai != null)                                                     {                                                         @foreach (var item in reclaimdetai.RequestFileList)                                                         {                                 ...

How to Change Layout based on viewbag value in mvc view using Mvc,C#

 @{     if (@ViewBag.lang == "en")     {         Layout = "Layout Name 1"; //This content uses above layout     }     if (@ViewBag.lang == "ar")     {         Layout = "Layout Name 2"; //This content uses above layout     } }

How to Get the current url and redirect to other url(case:button click english to arabic screen using parameter in url) using jquery,mvc,c#

   <a class="btn btn-icon btn-clean btn-lg w-40px h-40px btnlang" id="btnlang" > Change Lang </a> sample url:  https://localhost:44310/Claims/AddClaim?lang=en <script src="~/lib/jquery/dist/jquery.min.js"></script> <script>     $(document).ready(function () {         $('.btnlang').click(function () {             debugger;             var pageURL = $(location).attr("href");//gets the current url             var baseaddress = pageURL.substring(0, pageURL.indexOf('?'));//get the base address before '?'             var tech = getUrlParameter('lang');//gets the parameter using parameter name i.e,lang             if (tech == "en") {                 location.href = baseaddress + "?lang=ar";             }...

How to write Function to validate input password pattern in mvc using Jquery

 function validatepin(cpin) {     //var paswd = /^(?=.*\d)(?=.*[^a-zA-Z0-9])(?!.*\s).{8,8}$/;     if (containsCharacters(cpin) && containsNumber(cpin) && containsSpecialCharacters(cpin)) {                return true;     } else {                return false;     } } function containsCharacters(val) { var regex = /[A-z]/; var isValid = regex.test(val); return isValid; } function containsNumber(val) { var regex = /[0-9]/; var isValid = regex.test(val); return isValid; } function containsSpecialCharacters(val) { var regex = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/; var isValid = regex.test(val); return isValid; }

How to write api method to Read file and save it in ftp server using webapi c#

[Route("getdata")]         [HttpPost]         public string ReadFromAzureAS(string path)         {             //FTP Server URL.             string ftp = "ftp://localhost:21/";             //FTP Folder name. Leave blank if you want to upload to root folder.             string ftpFolder = "Uploads/";             string status = "File Transfer Failed";             FileStream stream = File.OpenRead(path);             byte[] fileBytes = new byte[stream.Length];             stream.Read(fileBytes, 0, fileBytes.Length);             stream.Close();             //Begins the process of writing the byte array back to a file      ...

Read any file using filepath and save it in a folder in c#

// Read file to byte array FileStream stream = File.OpenRead( @" c:\path\to\your\file\here.txt" ); byte [] fileBytes= new byte [stream.Length]; stream.Read(fileBytes, 0 , fileBytes.Length); stream.Close(); // Begins the process of writing the byte array back to a file using (Stream file = File.OpenWrite( @" c:\path\to\your\file\here.txt" )) { file.Write(fileBytes, 0 , fileBytes.Length); }

How to insert json data directly into table in sql.

Let us consider the below JSON as sample data, ex: [{ "info": [{ "id": 1, "name": "John", "surname": "Smith", "age": 25 }, { "id": 2, "name": "Abijal", "surname": "Smith", "age": 45 }, { "id": 3, "name": "Abhijit", "surname": "singh", "age": 41 }] }] To insert the above JSON we can use the below query, Query: declare @json varchar(max) =' [{ "info": [{ "id": 1, "name": "John", "surname": "Smith", "age": 25 }, { "id": 2, "name": "Abijal", "surname": "Smith", "age": 45 }, { "id": 3, "name": "Abhijit", "surname": "singh"...