|
It makes life easier for you. Consider it shorthand. It doesnt affect your compiled code at all. (You'll be surprised how many different ways you can do things before it changes the IL).
|
|
|
|
|
No, they don't adversely affect the program; they simply save the programmer many many many keystrokes. And my opinion of them is pretty well documented in that other thread so I won't repeat myself yet again other than to say, "I don't use them".
On the other hand, most practitioners don't advance beyond the very simplest use of the using directive.
For instance, one could write
using System.Collections.Generic ;
...
Dictionary<string,object> mystuff = new Dictionary<string,object>() ;
Dictionary<string,object> yourstuff = new Dictionary<string,object>() ;
Dictionary<string,object> hisstuff = new Dictionary<string,object>() ;
but one could also write
using LookupTable=System.Collections.Generic.Dictionary<string,object> ;
...
LookupTable mystuff = new LookupTable() ;
LookupTable yourstuff = new LookupTable() ;
LookupTable hisstuff = new LookupTable() ;
which has the benefits of saving even more keystrokes, makes the program easier to maintain (the definition of LookupTable only needs to be changed in one place), and may just be better OOP.
(And less time replacing <s with <s when posting on CP!)
Another use for the using directive is this
using DatabaseConnection=System.Data.SqlClient.SqlConnection ;
using DatabaseCommand =System.Data.SqlClient.SqlCommand ;
using DatabaseReader =System.Data.SqlClient.SqlDataReader ;
using DatabaseParameter =System.Data.SqlClient.SqlParameter ;
using DatabaseAdapter =System.Data.SqlClient.SqlDataAdapter ;
...
then, if the underlying database technology changes, only the using directives need be modified; again, simplifying maintenance.
Taking that to the next level, we can make the selection of the actual database classes a compile-time issue
# if SqlClient
using DatabaseConnection=System.Data.SqlClient.SqlConnection ;
using DatabaseCommand =System.Data.SqlClient.SqlCommand ;
using DatabaseReader =System.Data.SqlClient.SqlDataReader ;
using DatabaseParameter =System.Data.SqlClient.SqlParameter ;
using DatabaseAdapter =System.Data.SqlClient.SqlDataAdapter ;
...
# endif
# if OleDb
...
# endif
# if MySql
...
# endif
...
The problem with this technique is that one must ensure that one and only one of the database systems is defined -- this is an unfortunate side-effect of Microsoft gutting the C preprocessor for use with C#.
Using the standard C preprocessor, one can write
# define SqlClient 1
# define OleDb 2
# define MySql 3
# define UseDatabase 1
# if (UseDatabase==SqlClient)
using DatabaseConnection=System.Data.SqlClient.SqlConnection ;
using DatabaseCommand =System.Data.SqlClient.SqlCommand ;
using DatabaseReader =System.Data.SqlClient.SqlDataReader ;
using DatabaseParameter =System.Data.SqlClient.SqlParameter ;
using DatabaseAdapter =System.Data.SqlClient.SqlDataAdapter ;
...
# endif
# if (UseDatabase==OleDb)
...
# endif
# if (UseDatabase==MySql)
...
# endif
|
|
|
|
|
Good explanation on the different ways to use the using directive. It is unfortunate that we don't have a bit more in the preprocessor to at least allow the #define statments.
|
|
|
|
|
Oh, and I left out the use of the using directive to write
using WinForms=System.Windows.Forms ;
using WebForms=System.Web.UI.WebControls ;
...
WinForms.Button b1 = new WinForms.Button() ;
WebForms.Button b2 = new WebForms.Button() ;
(But then, only I would be crazy enough to do that.)
|
|
|
|
|
Nice, i like this one...
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Vodstok wrote: at the top of a .cs file
Which is another misconception... Did you know... that you can put a using directive inside a namespace? I didn't until the subject came in that other thread.
|
|
|
|
|
Hi,
I'm using VS2005 and I have a settings file in my project whose items are user-scoped. Is there way to save them to a different file instead of the auto-generated config file which is under the C:/Documents and Settings/blah blah blah....
|
|
|
|
|
use System.Xml or System.IO to write and read your own custom file...
|
|
|
|
|
|
Hi,
I need some information about calling events of web application through windows application by httpwebrequest nd response
Actually I want to execute all events of web application through request…., but I only succeed for server side control's event and not for client side control like anchor element like that…….
I am implementing all these from windows application…..., If u have any information then please reply….……..
Dipti Jadhav
|
|
|
|
|
What is the diff between Sender property of MailMessage and From property of MailMessage.
What is the difference between ReplyTO and ReturnPath
they have same meaning in usage. dont they ?
Now my client wants to use these things with unique cases
when a reciever hits reply it should use ReplyTo address (which it does)
When a mail is getting bounced or if there is some error then it should use ReturnPath
Man! Now it is coming down to client sending me RFCs and still i'm not able to figure out the difference and how i can utilize all these properties.
Regards
|
|
|
|
|
Have you looked at the RFC 2822[^] for email messages?
From §3.6.2 Originator fields
The "From:" field specifies the author(s) of the message,
that is, the mailbox(es) of the person(s) or system(s) responsible
for the writing of the message. The "Sender:" field specifies the
mailbox of the agent responsible for the actual transmission of the
message. For example, if a secretary were to send a message for
another person, the mailbox of the secretary would appear in the
"Sender:" field and the mailbox of the actual author would appear in
the "From:" field. If the originator of the message can be indicated
by a single mailbox and the author and transmitter are identical, the
"Sender:" field SHOULD NOT be used. Otherwise, both fields SHOULD
appear.
The originator fields also provide the information required when
replying to a message. When the "Reply-To:" field is present, it
indicates the mailbox(es) to which the author of the message suggests
that replies be sent. In the absence of the "Reply-To:" field,
replies SHOULD by default be sent to the mailbox(es) specified in the
"From:" field unless otherwise specified by the person composing the
reply.
In all cases, the "From:" field SHOULD NOT contain any mailbox that
does not belong to the author(s) of the message.
From RFC 2821[^], §6.1 If there is a delivery failure after acceptance of a message, the
receiver-SMTP MUST formulate and mail a notification message. This
notification MUST be sent using a null ("<>") reverse path in the
envelope. The recipient of this notification MUST be the address
from the envelope return path (or the Return-Path: line).
So...to directly your questions:
logicaldna wrote: What is the diff between Sender property of MailMessage and From property of MailMessage.
What is the difference between ReplyTO and ReturnPath
they have same meaning in usage. dont they ?
Now my client wants to use these things with unique cases
The "From:" field specifies the author(s) of the message. The "Sender:" field specifies the mailbox of the agent responsible for the actual transmission of the message.
The "Reply-To:" field (if it is present), indicates the mailbox(es) to which the author of the message suggests that replies be sent.
The "Return-Path" field indicates the mailbox that a delivery failure notification should be sent to.
You need to get specific cases, including all of the edge cases clearly documented from your client.
It sounds like you are trying to write an SMTP compliant email system. I'd recommend using one of the commercially available versions instead of trying to do it yourself as there are a ton of rules that need to be followed and some of them are fairly non-trivial.
|
|
|
|
|
Scott Dorman wrote: if a secretary were to send a message for
another person, the mailbox of the secretary would appear in the
"Sender:" field and the mailbox of the actual author would appear in
the "From:" field.
isn't that a spoofing ?
When a mail is generated and sent by system, i need to have a User Role ID (Persons ID ) at FROM and a Admin ID at Sender,
I can do this using SMTPClient but i can not mention Return path using the same
Scott Dorman wrote: It sounds like you are trying to write an SMTP compliant email system
No ways, i can live with whatever .net provides
Thanks for the details !
|
|
|
|
|
In a way it's spoofing. Essentially what is happening in this case is that the secretary is sending the email "on behalf of" the boss. According to the RFC rules, since the secretary actually sent the message that email address appears as the "Sender", but the bosses email address appears as the "From" since that is who actually authored the email.
There is a very fine line between true spoofing and following the rules of the RFC. In most cases spoofing is impersonating both the author and the sender.
If you are just uisng the email messaging capabilities of .NET to send the message, a lot of these rules should already be established for you. The Return-Path field is actually more a function of the actual SMTP system rather than the message, so it may already be present when the email is delivered. There are also rules for what happens if it isn't present at all, so it may not be an issue.
|
|
|
|
|
One more thing i noticed,
there is no suport for Return-path in SMTPClient 2.0
If i have
FROM
SENDER
REPLY-TO
RETURN-PATH (By putting additional header)
if mail is bounced back the bounce back mail goes to
SENDER insted of RETURN-PATH
if SENDER is not there then bounce back email goes to FROM address.
i just want to to send failed/bounced back emails to particular ID
Thanks !
|
|
|
|
|
This may be a factor of the SMTP server you are using. As I mentioned in my other response, Return-Path is more a factor of the SMTP server than the actual email message.
|
|
|
|
|
yea , Thanks for the information
|
|
|
|
|
I have three column CSV filed(id,Mobile_NO,Datesent).I want to insert this data in to a datatable and finally in to a database table with the same definition as CSV.
Please let me know asap.I am Using C sharp
Thanks
-- modified at 7:37 Tuesday 28th August, 2007
|
|
|
|
|
use System.IO to read the .cvs file one line at a time. Then as the lines are read-in from the loop preform a .split(',') on each read-in var as you save it into a jagged array. Then you'll have the matrix saved into a jagged array to write or use the data as you wish.
If you're saving this to a database and don't know how looking up information on ADO.NET will be helpful.
|
|
|
|
|
Could you please give me the start up the code!
Thanks for your time.
|
|
|
|
|
Something like this should get you stated if you fix the two or three errors in it
namespace cvsreadapp
{
class CVSreader
{
public static bool ReadFile(string sFileName, out string[][] saJaggedArray)
{
bool bReturnValue = false;
try
{
string[] sFile;
int i=0;
StreamReader srFileIO = null;
FileStream fsFileIO = null;
fsFileIO = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
srFileIO = new StreamReader(fsFileIO);
sFile = srFileIO.ReadToEnd().Split('\n');
saJaggedArray = new string[sFile.Length][];
foreach (string x in sFile)
{
saJaggedArray[i] = new string[3];
saJaggedArray[i] = x.Split(',');
}
srFileIO.Close();
fsFileIO.Close();
bReturnValue = true;
}
catch
{
bReturnValue = false;
}
return bReturnValue;
}
}
class MyApp
{
static void main(string[] args)
{
string[][] jaggedarray;
if (!CVSreader.ReadFile("mycvsfile.cvs", out jaggedarray))
{
Console.WriteLine("Error reading CVS file");
}
foreach (string[] i in jaggedarray)
{
foreach (string j in i)
{
Console.Write(string.Concat(i," "));
}
Console.Write('\n');
}
}
}
}
|
|
|
|
|
hint on the errors:
(I did this so you'd learn; cause this sounded like a homework assignment)
Error 1: check main to see if it is "correct" right
Error 2: look into how an "out" var works (IE does it have to be assigned to?)
Error 3: bReturnValue might be setup "incorrectly" and cause problems in the function
|
|
|
|
|
Hi everybody:
I posted this on Visual Studio forum, but it seems to be frozen a bit, so I move it here.
I have written (or rather I started writing) a control which I want to act as an container in design-mode. After some googling I find out how to preform that. But... there was an error.
After about hour spent on doing random operations in VS 2005 PE, I find out how to effectively recreate the error. When I add some child controls to my control, then I can run App and everything is OK. But if I then recompile the control's DLL, and go back to the App's designer, then all child controls disappear, regardless whether the line "myControl.Controls.Add(childControl); " is still present in the generated code...
Please help...
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
I have one large SQL table with over 50 columns and 300,000 rows. I want to read each row in this table, perform data validation, and write this data to several different tables in different tables in the same database. I want to be able to reference each column by name and enforce strong data typing. I need an overview of how to do this and, if possible some sample code.
Joseph Stanish
|
|
|
|
|
Hi,
I'm currently in the process of an Utility that is similar to the Query Analyzer.
I have assigned the Database name in app.config file and it works fine.
But now the problem is,I have to extract all the Databases from the LocalNetwork in the Listbox,
and i Require to change the Database name in the App.Config File at run time
according to the database that i select from the Listbox.
And here's the app.config file code..
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SQLQueryAnalyzer" value="Data Source=(local);Integrated Security=True;User ID=;Password=;Initial Catalog=Northwind" />
</appSettings>
</configuration>
hi,
Please anyone help me in finding out the solution.
BhuMan
|
|
|
|