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 returns a … Read more

When to use an Enum vs Struct

Enumerations aren’t interchangable with structs. They have completely different usages. A struct can have members and methods, but an enumeration can have only labels and values for the labels. You could use an enum to specify different behaviours of a system Let’s say you have a class Person and let’s say that for whatsoever reason … Read more

Categories c# Tags

There is no ViewData item of type ‘IEnumerable‘ that has the key country

In your action change ViewBag.countrydrop = item8 to ViewBag.country = item8;and in View write like this: Actually when you write @Html.DropDownList(“country”, (IEnumerable)ViewBag.country, “Select country”) or Html.DropDownList(“country”,”Select Country) it looks in for IEnumerable<SelectListItem> in ViewBag with key country, you can also use this overload in this case: See Working DEMO Example

How do I exit a foreach loop in C#?

Use break. Unrelated to your question, I see in your code the line: In this line, you take a boolean value (name.firstname == null). Then, you apply the ! operator to it. Then, if the value is true, you set Violated to false; otherwise to true. So basically, Violated is set to the same value as the original expression (name.firstname … Read more

How to get relative path of a file in visual studio?

When it is the case that you want to use any kind of external file, there is certainly a way to put them in a folder within your project, but not as valid as getting them from resources. In a regular Visual Studio project, you should have a Resources.resx file under the Properties section, if not, you can easily … Read more