This C# implementation can help you uploading a file through SFTP access.
C# solution to import & use a custom Font file while drawing/editing images.
Its very important to know your database stats while planning for some architectural update or database migration. The beforehand information would always add a plus to mitigate any risk and proactively take actions. Below is SQL Server script that provides information about database stats which include list of all tables, there respective record count, allocated …
Getting fully qualified absolute path of ASP.NET application is always tricky and problem arises when code moves across various platform. Hard coding the Application Path is no where a good solution here. The URL syntax is:
Two solutions that you can look for in such scenarios: 1. Add an entry in your web.config file …
Below is the ASP.NET C# implementation of Uploading binary data like images as POST request to target URL:
private bool UploadFile(string PostURL)
int contentLength = fileUpload.PostedFile.ContentLength;
byte data = new byte[contentLength];
fileUpload.PostedFile.InputStream.Read(data, 0, contentLength);
// Prepare web request...
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(PostURL);
webRequest.Method = "POST";
webRequest.ContentType = "multipart/form-data";
webRequest.ContentLength = data.Length;
using (Stream postStream = webRequest.GetRequestStream())
// Send the data.
postStream.Write(data, 0, data.Length);
catch (Exception ex)
//Log exception here...
The binary data so posted can be retrieved on target post URL using below code:
byte Image = ReadFully(Request.InputStream);
public static byte ReadFully(Stream input)
byte buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
ms.Write(buffer, 0, read);
This scenario is very handy specifically in establishing communication between two different web technologies. For example: You can POST image …
Synchronization of data from Production to Development environment is merely a task of taking backup of Production DB, restoring it to Development environment and running to cleanup scripts to hide/overwrite user-specific critical information. This is pretty straight forward and does not even require domain knowledge. However, reverse is tricky, risky & surely need good insight …
When your server is behind any proxies or load balancers, the remote IP@ gets masked. In such scenarios, the server variable “REMOTE_ADDR” may not provide the correct client IP@. The only way to get remote addresses is to check if the proxies rewrite the request headers which most of them does. You can look through …
The reason behind this question lies in HTTP protocol. Strange but it’s true. HTTP is a stateless protocol. Each request is serviced as it comes; after the request is processed, all of the data is discarded. No state is maintained across requests even from the same client. This would typically mean that all information associated …
Many times we fall in a situation where we have implemented detection of file type based on file extension. It’s pretty easy to do that on both client as well as server side. But does it guarantees that file uploaded is not actually an “exe” file. Well, anyone can rename an “abc.exe” to “abc.txt” and upload it to your …
Below image depicts the focus areas if you are considering Performance Tuning as area of interest. As a developer, you can only control Platform (by configuring the hosting environment as per application requirement) & Application (by optimizing design & code implementation with due consideration of functional requirements) and these should be the key focus areas. …
Singleton Pattern: it involves only one class which is responsible to instantiate itself, to make sure it creates not more than one instance; in the same time it provides a global point of access to that instance. Below implementation is a step forward with aim to make it generic so as to decouple it from …
Maintain three branches of code: N, (N+1) and (N+2): Branch N corresponds to Prod version Branch (N+1) corresponds to QA version Branch (N+2) corresponds to DEV version Access right to each branch needs to be separately given depending upon the team or person working on particular phase of implementation. This task can be assigned to …