Asp.net File Upload Control Using with just one step

by munnaonc 27. May 2007 19:12

In our projects sometimes we need to use the file upload control. Asp.net 2.0 have
a build-in File-upload. In asp.net 1.x web controls didn’t had any builtin file-upload
control. Then we had to use a html input tag with type attribute set to “file” and
to use in server side add runat=”server” attribute.

<input id="myfileuploader" type="file" runat="server"/>

We all know how to work with a file upload control, today we will be discussion
about a new approach of file-upload. file-upload consists of two step . first we
have to select the file and then submit the page with a button or some kind of other
mechanism. To day we will try to minimize one step. If we want to upload the file
with just one step that is selecting the file here is the Technique

A file upload control which is eventually truned into a input html element have
three client side events

    * onBlur      
    * onChange
    * onFocus

we will utilize the onChange event… here is what we will do. frist add a asp.net
2.0 fileupload control in our page. then in pageload event add a attribute in attribute
collection. then write a javascript funtion to submit the form and in code do what
ever we whan….

 
task 1 : add a fileupload control

task 2: add the onchange attribute as FileUpload1.Attributes.Add("onchange", "doSomeStuff()");

task 3: add the javascript to submit the page

<script language="javascript"
type="text/javascript">

function doSomeStuff()
{

         document.forms[0].submit();

}

</script>

Thats it you are good to go.. in page load event check wheither the filename is
empty or not and then do the file upload.

VS templates not working? Easy to get things back.

by munnaonc 6. March 2007 20:59

Recently I had to work with window SharePoint Service 3.0 and its development. I download the visual studio 2005 project templates for SharePoint development. I downloaded the project msi from Microsoft download site.

http://download.microsoft.com/download/e/8/a/e8aa8476-5af6-4f38-aed2-0247a99d2bc6/VSeWSS.msi

Installed in my local computer… but when I opened the IDE2005 project templates are not there…..

I got confused… and try reinstall the msi… but noting happed… I went to google and found few people is also suffering from this problem… the problem is my vs2005 is installed in different drive other that “c:\” and the installed temples are in default “c:\”… and then I moved my template in the drive where the IDE2005 is installed….

Location of the project templates is [your dive letter]:\Program Files\Microsoft Visual Studio 8\Common7\IDE…

There were two directories one if project template and other is item template… last thing that I did is to make ide identity the project templates….

For this I had to just a command in vs2005 comma prompt..

devenv /installvstemplates

I found help from the following forum… please go there for more detailed discussion…

http://geekswithblogs.net/ehammersley/archive/2005/11/08/59451.aspx

Hope this will help someone someday….

Install assembly into Global Assembly Cache

by munnaonc 3. March 2007 20:52

Option One

Step One add the sn.exe to External Section of VS2005

1. Click on Menu->Tools->External Tools
2. A window with all external tool listed will popup.. click on add button
3. In title type “String Name tool”
4. In command brows for sn.exe tool [Generally in the bin directory of your sdk folder]
5. Check the use output window and prompt for argument check box…
6. Click on apply to dismiss the widow…

Now you can see that in tools menu you will have a menu item named “Strong Name Tool”. Click on the menu will launch a window asking the argument …. In the argument text box type

–k “c:\\mykeypair.snk”Click on okey to dismiss the window… in output window you will see that successful keypart creation message will be shown…

Your key is reated but not yet associated with any

Adding the key to the project to associate with assembly1. Open your project…
2. Open the property of the project…
3. You will see a tab called signning is bottom of the window… click on the signning button
4. In siginning tab check the sign the assembly check box.
5. In choose a strong name key file … click on brows …. And brows for your mykeypair.snk file…
6. save the project and build it…

That’s it your assembly is strong name signed on….

Option Two [Too Easy]

1. Open your project…
2. Open the property of the project…
3. You will see a tab called signning is bottom of the window… click on the signning button
4. In siginning tab check the sign the assembly check box.
5. In choose a strong name key file … click on new…
6. A window asking for snk file will popup… type the desiered name and click on okey to dismiss the window… save the project and build it…

That’s it your assembly is strong name signed on….

Deploy the assembly in GAC…

1. Add the gacutil.exe tool just like the sn.exe tool
2. Now open the gacutil tool from tools….
3. In the argument window type….
4. -i "$(ProjectDir)\bin\debug\DataBaseHelper.dll" or [-I “yourprojectdir\buildmode[debug or release]\bin\filename.dll”]
5. Click on okay to dismis the window..
6. In output window you will see a successful message….
7. “Assembly successfully added to the cache”

Happy programming!

Tags: , , , , , ,

.net | .net 1.1 | .net 2.2 | .net 3.0 | .net 3.5 | dll | GAC

Try.Catch. is not a good Practice

by munnaonc 12. September 2006 20:09
I don’t know using try catch in your code is good or bad. But I am sure that it makes your code run more slowly. For the early edge of my programming carrier I believed that c# language has managed the try catch or exception handling quite well. So we can use try catch as much as we can in our code to deal with the exception. But while working on the International Tax Expert project I found try catch is making my program working slow... this happens specially in paring a string to integer.

Let say

We have a code portion like

bool IsValidInteger(string s)
{
try
{
int x = int.parse(s);
return true;
}
catch
{
return false;
}
}

If we manage to provide an invalid string which is not an integer the program returns the accurate value that is false. And for only one case this works fine and no performance degradation occurs.

But if we have to fill a data grid which has 1000 rows and one columns value is filed using the above mentioned function to show an icon or assign formatting for the data to show on the cell. The performance hit shows, and the program run slow.

So it is better to avoid “try catch” as much as you can in your code, there is always a good way to code such things. We should always remember coding is also an art and we can make it stylish.

Our senior software Engineer Hasan Shahriar Masud provided a good example on this matter the example is given bellow.

“We should not use try-catch if we can logically conclude the exception. It will help the performance, which munna(that is me) proved.

For example

//We should not write
Try
{
C=A/B;
//Do Something 1
}
Catch
{
//Do Something 2
}
//We should write
If (B==0)
{
Do Something 2
}
Else
{
C=A/B;
//Do Something 1
}
I have investigated this on Xceed grid 3.1 in case of data convertion. May be its a problem of xceed grid.

Tags: , , , , ,

Xceed | .net 3.5 | .net | .net 1.1 | .net 2.2 | .net 3.0