There is actually a (subtle) difference between the two. Imagine you have the following code in File1.cs:
// File1.cs
using System;
namespace Outer.Inner
{
class Foo
{
static void Bar()
{
double d = Math.PI;
}
}
}
Now imagine that someone adds another file (File2.cs) to the project that looks like this:
// File2.cs
namespace Outer
{
class Math
{
}
}
The compiler searches Outer
before looking at those using
directives outside the namespace, so it finds Outer.Math
instead of System.Math
. Unfortunately (or perhaps fortunately?), Outer.Math
has no PI
member, so File1 is now broken.
This changes if you put the using
inside your namespace declaration, as follows:
// File1b.cs
namespace Outer.Inner
{
using System;
class Foo
{
static void Bar()
{
double d = Math.PI;
}
}
}
Now the compiler searches System
before searching Outer
, finds System.Math
, and all is well.
Some would argue that Math
might be a bad name for a user-defined class, since there's already one in System
; the point here is just that there is a difference, and it affects the maintainability of your code.
It's also interesting to note what happens if Foo
is in namespace Outer
, rather than Outer.Inner
. In that case, adding Outer.Math
in File2 breaks File1 regardless of where the using
goes. This implies that the compiler searches the innermost enclosing namespace before it looks at any using
directive.
This turned out to be caused by the FileUpload Control being rendered during a partial page update. To submit properly the FileUpload control needs to be rendered and submitted using full post backs. Because the first form submit caused a full post back, the upload began working as intended the second time around.
Solution:
Add both of the buttons that display and submit the file upload control to the update panels post back triggers.
eg:
<Triggers>
<asp:PostBackTrigger ControlID="btnShowUploadForm" />
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
Best Solution
I know of a third party component that can do that. It's called "swfupload" and is free to use and open source, and uses javascript and flash to do the magic.
here is a list of the features they offer: (from their site)
They also have a demo area where you can play around with their control. That way you can make sure it is exactly what you want.
We used it in one of our projects and it has never failed us so far, so I think this is a safe bet.
oh and here is the download page: http://code.google.com/p/swfupload/