Posts

Showing posts from May, 2020

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); }