Tuesday, June 23, 2009

CSV File Delimiters

In a *.csv file, a comma and newline characters are main delimiters. The escape character for csv files is the double-quotes.

Thursday, June 18, 2009

List.Contains(T obj)

I don't think it is worth using this on most occasions.

First, this is BigO(n), which is the same as linearly searching the list.

Secondly, if you have a complex object, you must implement IEqualityComparer interface, which only has a GetHashCode method, which returns an int.

I don't think this is too useful.

Error 1 Inconsistent accessibility: parameter x type is less accessible than method y

I was trying to pass an interface type to a method.

public void MyMethod(IMyInterface myI)
{
// ...
}

Make the interface public

public interface IMyInterface
{
// ..
}

This should solve this problem.

Tuesday, June 16, 2009

C# 3.5 ParameterizedThreadStart

I wanted to create a Thread that would take a parameter to do concurrency in my project.

This is how I did it.
Thread is in the namespace System.Threading

{
Thread newThread = new Thread(new ParameterizedThreadStart([MethodName]);
newThread.Start([parameter]);
}

[MethodName](object [parameter])
{
// do something
}

So, the key is making the parameter object type. In the method that you created a new thread, convert the object into the datatype that it is.

Monday, June 15, 2009

Question Mark Operator C#

The question mark operator is a 'ternary' operator that allows a conditional statement to be written in one line.

if a function returns a boolean :

return someVar == anotherVar ? true : false;

is equivalent to

if(someVar == anotherVar)
{
return true;
}
else
{
return false;
]

Friday, June 12, 2009

Loading Gif with ASP.NET MVC and AJAX

I wanted a loading gif to show while the webapp was doing work. It would take a while. I, also, wanted the gif to go away once the response came back to the user.

Put the loading gif in the div that is replaced. I thought it was a good idea.

User download a file ASP.NET MVC with AJAX

I wanted the user to be able to download a file, using ASP.NET MVC with AJAX. The problem wasn't downloading, or AJAX. It was the two together.

It's really simple. What you need to do is get the path of the file to download, put the value in ViewData and make an href to that file with value "Download" to target="_blank". This will show a popup to download the file.

[lt]a href='[lt]%=path%[gt]' target="_blank" [gt] Download [lt]/a[gt]

[lt] = "<"
[gt] = ">"

Thursday, June 11, 2009

Show Loading gif on button click

I wanted to show a loading gif on a user button click, because the action would take a while. So this is the solution I found.



You make the div style.display = "none;" then on button click, you set the style.display = "";

Wednesday, June 10, 2009

Current Directory Path C#

I wanted to get the current directory in a ASP.NET MVC application on the c# side.

System.Environment.CurrentDirectory

-- gets or sets the fully qualified directory.

HOWEVER, this may not be what you are looking for as, this is sometimes

../ProgramFiles/MicroSoftVS/Common7/IDE/

Tuesday, June 9, 2009

ASP.NET MVC Dropdownlist Values on Server

I wanted to get the values directly from the dropdownlist on the server. For example, I wanted to make a drop down list, and when the user chose either one or multiple values, make a query on the server based on those values.

Well, you can't just write the "select" tag html and expect to get those values on the server. If you want to directly write the html tag, I had to make hidden fields, when the user chose a value in the dropdownlist, make the hidden field's value the value of the dropdownlist.

Well, there is a way. Use the html helper for a dropdownlist.

Before making the dropdownlist, make a dictionary of KeyValuePairs and Values.

The KeyValuePairs are the Key and Values, and the Values are just the values.

You can just make a dictionary and have just the key and values. This will work if you just need the keys on the server side.


The KeyValuePair is just if you want both the key and value on the server. If not, then just make a dictionary of string,string. Where the "new SelectList(d, 'Key', 'Value')" shows, the Key is what is sent to the server, and the value is what is shown to the user. You can change "Key" to "Value" and the value will be sent.

On the server side, you should have a List[string] Name as the variable to receive the data. It can be just "string" but you will only get the first selected key if multple are selected, where the list makes it possible to get all selected keys. If you send back a KeyValuePair as a key, then the values will look like "[key,value]".

Tuesday, June 2, 2009

ListBox in Html

List boxes in HTML are called 'select'. Each value is called 'option'. These 'select' and 'option' are tags with '<' and '>', but Blogger won't let you writing these explicitely.

A dropdownlist will be displayed unless you add ' size="###" ' as an attribute, where ### is greater than 1.




Monday, June 1, 2009

I.E. HTML Colors

I found out today that Firefox, Chrome, Opera, and Safari ( 3.0.3, 2.0.175, 9.63, 3.2.2) will accept the html shortcut for #808080 as 'grey', but I.E. 7.0.5 won't. I.E. will take 'gray'. I will resort to using the hex code from now on.