|
thanks for that, yes the file is accessible from http.
Yet to implement that code but my guess is, it would prompt the user to download that file. Is that possible if we can just save the file in a specific place instead of prompting.
Kaliem
|
|
|
|
|
Kaliem,
See my first response to your question. The component described in the article does what you are asking. It takes a URL to a file over HTTP and downloads it to a given location.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Because the process being started is IE it will attempt to open the file just as any valid URI, however because of the file association IE will use MS Excel as the viewer. There is no need to download the file.
only two letters away from being an asset
|
|
|
|
|
Given the following class hierarchy and simple Program.Main
using System;
using System.Collections.Generic;
using System.Text;
namespace GenericTest
{
class Base
{
public void Name()
{
Console.WriteLine("I'm a Base class");
}
};
class Middle : Base
{
public new void Name()
{
Console.Write("I'm a Middle class");
}
};
class Child : Middle
{
public new void Name()
{
Console.Write("I'm a Child class");
}
};
class Program
{
static void PrintName<t>( T instance ) where T : GenericTest.Base
{
instance.Name();
}
static void Main(string[] args)
{
Child c = new Child();
PrintName<child>( c );
}
}
}
I see the following output
I'm a Base class
And I would have expected to see
I'm a Child class
Is this a bug with Generics or is it a side effect of how the Generic is generated for reference types?
Thanks
Matt Schuckmann
|
|
|
|
|
Hi,
it is correct by definition of the C# language.
You tell PrintName it is accepting objects of type Base,
hence instance.Name() actually is a call to Base.Name().
Exactly the same thing would happen when you do:
static void SomeMethod(Base instance) {
instance.Name();
}
If you want to get Child.Name() you should make Name() virtual and override it,
instead of using the "new" keyword.
|
|
|
|
|
The wayI understood the where statement is that I'm telling it to accept objects derived from type Base or that have the same interface as type Base. If I wanted to tell it to accept objects of type Base I wouldn't use a Generic I'd just use a simple method, like you suggested.
So your basically telling me that within a Generic you lose all static type information and everything is staticly bound and treated as if it was the type specified in the where statement. This is really sad your basicly telling me that a generic is no better than a class or method that takes a common ancestor class for whatever types you're going to pass it.
I understand making the method virtual to accomplish the intended results of this example but for reasons out side of this example I don't want the method to be virtual and I wanted to use the hiding semantics of the new keyword.
Thank You
Matt S.
|
|
|
|
|
mschuckmann wrote: The wayI understood the where statement is that I'm telling it to accept objects derived from type Base or that have the same interface as type Base.
That is correct; and it also applies to SomeMethod() in my example.
mschuckmann wrote: within a Generic you lose all static type information
That is not correct: you dont loose all information, both the Generic method and the
SomeMethod method accept Base objects or Base derivatives, and these objects keep their characteristics.
It is only the way you define your classes (thru the virtual/override/new keywords)
that decides whether you get the functionality of the base method or the more specialized
method. That has nothing to do with generics.
C# offers two ways to get the specialized method: by using the specialized type (Child.Name),
or by using virtual methods.
mschuckmann wrote: a generic is no better than a class or method that takes a common ancestor class
That is correct if you use where T : type.
But generics can be used without type constraint (acting somewhat like C++ templates).
And they can be used with more complex constraints; read up on "where" in MSDN for that.
|
|
|
|
|
Luc Pattyn wrote: That is not correct: you dont loose all information, both the Generic method and the
SomeMethod method accept Base objects or Base derivatives, and these objects keep their characteristics.
The objects themselves may keep their characteristics, because after all they are objects, but they no longer behave like themselves the with respect to non-virtual methods and this is counter intuitive to anyone who has done extensive template programing.
Luc Pattyn wrote: It is only the way you define your classes (thru the virtual/override/new keywords)
that decides whether you get the functionality of the base method or the more specialized
method. That has nothing to do with generics.
But the symantics of how they've implimented the generic feature makes the object behave differently with in the code of the generic (effectively making it lose it's type within the Generic), what is the point of providing the generic with specific type information (i.e. printName<child>(c) ) on the type I'm passing it if it's just going to ignore it and staticely the object to the lowest common denominator implimentation for non-virtual methods. In my opinion this hugely limits the functionality of generics when compared to templates and I find it hard to believe that anyone actually thinks this is good behavior.
Luc Pattyn wrote: That is correct if you use where T : type.
But generics can be used without type constraint (acting somewhat like C++ templates).
And they can be used with more complex constraints; read up on "where" in MSDN for that.
If you leave out the where constraint you've essentially specified a generic with a constraint of object and you can't call any methods except those declared by object. Therefore my example code will not compile without the where constraint. So sure you can impliment generics without type constraints but don't expect to do anything interesting in your generic code.
C++ templates effectively impliment constraints but much more flexibly and without any new confusing and limiting syntax. They do this by verifying any type they are instantiated with impliment (or claim to impliment) any methods that are is used by the template at compile time.
Thanks again
Matt S.
|
|
|
|
|
mschuckmann wrote: If you leave out the where constraint you've essentially specified a generic with a constraint of object and you can't call any methods except those declared by object. Therefore my example code will not compile without the where constraint. So sure you can impliment generics without type constraints but don't expect to do anything interesting in your generic code.
I do agree to your point of view, that the limitation of generics in regard to derived classes are unexpected. As a workaround you can use an interface, that defines the required methods, as the constraint. However, you must explicitly specify the interface for each class:
interface Named
{
void Name();
};
class Base : Named
{
public void Name()
{
Console.WriteLine("I'm a Base class");
}
};
class Middle : Base, Named
{
public new void Name()
{
Console.Write("I'm a Middle class");
}
};
class Child : Middle, Named
{
public new void Name()
{
Console.Write("I'm a Child class");
}
};
class Program
{
static void PrintName<T>( T instance ) where T : Named
{
instance.Name();
}
static void Main( string[] args )
{
Child c = new Child();
PrintName( c );
Console.ReadLine();
}
}
Regards,
Tim
|
|
|
|
|
I am trying to Bind data to DropDownLists and a CheckBox on differents Views of the MultiView. However I get an error whenever I try to Bind the Data. I did it in the Code Behind but cannot figure out what event in what object I should be putting the code in. Can anyone assist?
~Candi
|
|
|
|
|
Hope the Article by verinder bindra here[^] in CP will help you.
Regards,
Satips.
|
|
|
|
|
I have to insert 173 values from a DataTable into 173 existing fields in a SQL table. The values are of all different types. Any suggestions on doing this without taking a very very long way? Thank you!
Vicky
|
|
|
|
|
kissa49 wrote: Any suggestions on doing this without taking a very very long way?
By writing a simple C# program to do it?
|
|
|
|
|
right. i can just do an insert statement, except i have 173 fields and i have to specify each name and cast each data type
Vicky
|
|
|
|
|
Do you have a specific problem you need solving because we'll need more information if we're to help you?
|
|
|
|
|
Find your DBA, and ask him to write you a stored procedure for the insert on his massively dumb table, 173 columns is insane!
|
|
|
|
|
Yes, its a general table that gets normalized later. I have a DataTable containing the data that needs to go into this table. i was trying to do SQLBulkCopy, but that wouldnt work before the fields in the SQL table are of different data types and what goes in are Strings. So... I was trying to do insert SQL statements from the code.
Vicky
|
|
|
|
|
What's the source of the data? How does it get into the DataTable?
|
|
|
|
|
I write it into the table from a txt file
Vicky
|
|
|
|
|
When I have to do something like that I use bcp , the SQL Server command-line utility for bulk copy, to load the raw data into a (temporary) table and I have a trigger on the table that handles converting and moving the data to the actual destination(s).
Be sure to specify -h"FIRE_TRIGGERS" when running bcp .
|
|
|
|
|
perhaps you would like to share some details on that trigger?
Thanks.
Vicky
|
|
|
|
|
Sure, I'll work up an example if you like.
-- modified at 20:12 Tuesday 3rd July, 2007
And is it CSV or some other format?
|
|
|
|
|
The data is already in a DataTable in strings. I need to transfer that data into fields into an existing SQL table. The fields are all set to different data types so I have to cast the strings to whatever the fields are.
Vicky
|
|
|
|
|
hi guys, I need help to read a block of data from a text file.
I m using StreamReader object and its method ReadBlock, which is supposed to write certain number of characters into a char[] buffer, but when I debug the code actually the buffer is not being written, all the values are empty.
Please help.
|
|
|
|
|
Show the code, including var declarations and initialization, plus any errors/exceptions.
Does it work at all ? up to a point ? or what ?
|
|
|
|