Posts

Opening landscape image in c#

Bitmap   source  = ( Bitmap ) Image . FromFile (path);                                                           if  ( Array . IndexOf ( source .PropertyIdList, 274) > -1)                     {                          var   orientation  = ( int ) source . GetPropertyItem (274).Value[0];                          switch  ( orie...

405 - HTTP verb used to access this page is not allowed

Just add the following config in the web.config file  <system.webServer>   <modules> <remove name="WebDAVModule" />   </modules>       <handlers> <remove name="WebDAV" />       </handlers>     </system.webServer>

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

The default json size configured in asp.net mvc is 2097152. You can change it or add in the web.config < configuration > < system.web.extensions > < scripting > < webServices > < jsonSerialization maxJsonLength = "50000000" /> </ webServices > </ scripting > </ system.web.extensions > </ configuration >

How to download file from the blob storage in CSharp

To download a file from a blob storage, first you have to download the reference or assembly from the nuget package "Azure.Storage.Blobs". You also have to obtain the connection string from azure blob storage account private BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); var container = _blobServiceClient.GetBlobContainerClient(containerName); await container.CreateIfNotExistsAsync(Azure.Storage.Blobs.Models.PublicAccessType.BlobContainer); var blob = container.GetBlobClient("image.png"); await blob.DownloadToAsync("c:\users\documents\image.png");

Asp.net core swagger not showing parameter description

In order to display the description of the parameter specified in the action. You have to enable xml generation in your project property and enable it in swagger option. services.AddSwaggerGen(swagger => { swagger.SwaggerDoc("v1", new OpenApiInfo { Title = "ArchiveOne WebApi", Version = "v1" }); var basePath = PlatformServices.Default.Application.ApplicationBasePath; foreach (var name in Directory.GetFiles(basePath, "*.XML", SearchOption.AllDirectories)) { swagger.IncludeXmlComments(name); } });

This CodeDomProvider does not support this method

This error occurs when you try to parse CSharp code using CodeDomProvider . CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); var compileUnit = provider.Parse(File.OpenText(filename)); In order to parse existing CSharp code you have to use Roslyn or other parser.

How to add custom header in swagger operation

Image
I am currently developing a .net core web API that will use a swagger as its documentation.  Everything was perfect, except almost of the request method has a required data that was in the header.  My problem was how to add an input header in the Swagger UI. After a few research, I found it. Here's how to do it. Create a filter class that implement IOperationFilter public class MyCustomHeaderFilter : IOperationFilter { public void Apply(OpenApiOperation operation, OperationFilterContext context) { if (operation.Parameters != null) { operation.Parameters.Add(new OpenApiParameter { Name = "FilterName", In = ParameterLocation.Header, Description = "access token", Required = false, }); } } } Register the class in swagger using OperationFilter ...