If a folder does not exist, create it

As others have said, use System.IO.Directory.CreateDirectory. But, you don’t need to check if it exists first. From the documentation: Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. If the directory already exists, this method does not create a new directory, but it … Read more

Ajax request returns 200 OK, but an error event is fired instead of success

jQuery.ajax attempts to convert the response body depending on the specified dataType parameter or the Content-Type header sent by the server. If the conversion fails (e.g. if the JSON/XML is invalid), the error callback is fired. Your AJAX code contains: dataType: “json” In this case jQuery: Evaluates the response as JSON and returns a JavaScript … Read more

Change the selected value of a drop-down list with jQuery

jQuery’s documentation states: [jQuery.val] checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values. This behavior is in jQuery versions 1.2 and above. You most likely want this: $(“._statusDDL”).val(‘2’); Add .change() to see the option in the dropdown list frontend: $(“._statusDDL”).val(‘2’).change();

How do you set the Content-Type header for an HttpClient request?

The content type is a header of the content, not of the request, which is why this is failing. AddWithoutValidation as suggested by Robert Levy may work, but you can also set the content type when creating the request content itself (note that the code snippet adds application/json in two places-for Accept and Content-Type headers): … Read more

Maximum request length exceeded.

If you are using IIS for hosting your application, then the default upload file size is 4MB. To increase it, please use this below section in your web.config – <configuration> <system.web> <httpRuntime maxRequestLength=”1048576″ /> </system.web> </configuration> For IIS7 and above, you also need to add the lines below: <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength=”1073741824″ /> </requestFiltering> … Read more

Could not find a part of the path … bin\roslyn\csc.exe

TL; DR run this in the Package Manager Console: Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r More information This problem is not related to Visual Studio itself, so answers suggesting adding build steps to copy files over are rather a workaround. Same with adding compiler binaries manually to the project. The Roslyn compiler comes from a NuGet package and … Read more

JavaScriptSerializer – JSON serialization of enum as string

I have found that Json.NET provides the exact functionality I’m looking for with a StringEnumConverter attribute: using Newtonsoft.Json; using Newtonsoft.Json.Converters; [JsonConverter(typeof(StringEnumConverter))] public Gender Gender { get; set; } More details at available on StringEnumConverter documentation. There are other places to configure this converter more globally: enum itself if you want enum always be serialized/deserialized as … Read more

Path.Combine for URLs?

Uri has a constructor that should do this for you: new Uri(Uri baseUri, string relativeUri) Here’s an example: Uri baseUri = new Uri(“http://www.contoso.com”); Uri myUri = new Uri(baseUri, “catalog/shownew.htm”); Note from editor: Beware, this method does not work as expected. It can cut part of baseUri in some cases. See comments and other answers.

A potentially dangerous Request.Form value was detected from the client

I think you are attacking it from the wrong angle by trying to encode all posted data. Note that a “<” could also come from other outside sources, like a database field, a configuration, a file, a feed and so on. Furthermore, “<” is not inherently dangerous. It’s only dangerous in a specific context: when … Read more

How do I format a Microsoft JSON date?

eval() is not necessary. This will work fine: var date = new Date(parseInt(jsonDate.substr(6))); The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor. I have intentionally left out the radix (the 2nd argument to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)