Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<appSettings>
    <add key="fromemailid" value="development@relone.com"/>
  </appSettings>

on codebehind i am using the following code to get frommailid
MailAddress from = new MailAddress(ConfigurationSettings.AppSettings("fromemailid"));

but iam getting
"non-invocable member 'System.Configuration.ConfigurationSettings.AppSettings' cannot used like a method".
What should I do to overcome this error....Please help me.
on default.aspx.cs page
if (conn.send_mail(tomailid)) 

Error	1	Member 'WorkflowSystem.DataAccess.connection1.send_mail(string)' cannot be accessed with an instance reference; qualify it with a type name instead	C:\Users\user\Desktop\WebApplication1\WebApplication1\Default.aspx.cs	73	25	WebApplication1

on connection.cs page
C#
public static bool send_mail(string toemailid)
        {
            MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].ToString());
        }

Error	2	'WorkflowSystem.DataAccess.connection1.send_mail(string)': not all code paths return a value	C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs	110	28	WebApplication1

What is to be done now...Please help me.
Posted
v3
Comments
What is the "conn" in if (conn.send_mail(tomailid)) ?
Member 8701813 19-Feb-13 12:13pm    
on default.aspx.cs page:
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
WorkflowSystem.DataAccess.connection1 conn = new WorkflowSystem.DataAccess.connection1();
protected void btnSubmit_Click(object sender, EventArgs e)
{


try
{
// Get the HttpFileCollection

HttpFileCollection hfc = Request.Files;
fn = new string[hfc.Count];
documentlocation = new string[hfc.Count];
docloc = new string[hfc.Count];
for (int i = 0; i < hfc.Count; i++)
{

HttpPostedFile hpf = hfc[i];

if (hpf.ContentLength > 0)
{
fn[i] = Path.GetFileName(hpf.FileName);
docloc[i] = Path.GetFullPath(hpf.FileName);
hpf.SaveAs(@"D:\testfiles\" + fn[i]);
documentlocation[i] = location + fn[i];
}
}
int j = conn.insert_update_request("Insert", 6, Convert.ToString(docloc[0]),Convert.ToString(docloc[1]),Convert.ToString(docloc[2]), txtdescription.Text.ToString(), 1, txtApplicationFormId.Text.ToString());
if (j > 0)
{
dt = conn.select_mailid(6);
if (dt.Rows.Count > 0)
{
tomailid = (string)dt.Rows[0][0];
}
if (conn.send_mail(tomailid))
{
}
}
}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
on connection.cs page:
namespace WorkflowSystem.DataAccess
{
public class connection1
{
public SqlConnection connection;
public connection1()
{
try
{
string cwfs = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["WorkflowSystem"].ConnectionString;
connection = new SqlConnection (cwfs);
}
catch(Exception objex)
{
Console.WriteLine(objex.Message);
}
}
public DataTable select_mailid(int usertypeid)
{
DataTable dt_select_mailid = new DataTable();
try
{
connection.Open();
SqlCommand cmd = new SqlCommand("sp_select_mailid_by_usertypeid", connection);
cmd.Connection = connection;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@usertypeid", usertypeid);
SqlDataAdapter da = new SqlDataAdapter(cmd.ToString(), connection);
da.SelectCommand = cmd;
da.Fill(dt_select_mailid);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
return dt_select_mailid;
}
public int insert_update_request(string type, int usertypeid, string document1location, string document2location, string document3location, string descr, int statusid, string appid)
{
int i;
try
{
connection.Open();
SqlCommand cmd = new SqlCommand("sp_insert_update_request", connection);
cmd.Connection = connection;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@type", type);
cmd.Parameters.AddWithValue("@usertypeid", usertypeid);
cmd.Parameters.AddWithValue("@doc1location", document1location);
cmd.Parameters.AddWithValue("@doc2location", document2location);
cmd.P
Member 8701813 19-Feb-13 12:21pm    
continuation....
cmd.Parameters.AddWithValue("@description", descr);
cmd.Parameters.AddWithValue("@statusid", statusid);
cmd.Parameters.AddWithValue("@applicationid", appid);
i = cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
i = 0;
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
return i;
}
public static bool send_mail(string toemailid)
{
MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].ToString());
MailAddress to = new MailAddress(toemailid);
MailMessage mm = new MailMessage(from, toemailid);

}
this is my code...i think now u might have an idea why i am conn.send_mail(tomailid)...
still i have to write ...any help is appreciated..
Member 8701813 19-Feb-13 12:43pm    
continuation..
public static bool send_mail(string toemailid)..here i am getting toemailid from database.
{
MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].ToString());
MailAddress to = new MailAddress(toemailid);..is this statement correct?
MailMessage mm = new MailMessage(from, toemailid);...here i am facing pbm
mm.Subject = "mail sending";
mm.Body = "mail sending";
SmtpClient client = new SmtpClient();
try
{
client.Send(mm);
return true;
}
catch (Exception ex)
{
Console.Write(ex.Message);
return false;
}

}
Please check my Updated answer under heading "Update".

Thanks...

You are using wrong brackets.
Rewrite your code as
C#
MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].toString());
 
Share this answer
 
v2
1.

"non-invocable member 'System.Configuration.ConfigurationSettings.AppSettings' cannot used like a method"

Do like below (as suggested by @CodeMaster_Noob).
C#
MailAddress from = new MailAddress(ConfigurationSettings.AppSettings["fromemailid"].toString());


2.

"not all code paths return a value"

The method signature of "send_mail" is...
C#
public static bool send_mail(string toemailid)

where return type is "bool" not void.
But you have not returned anything. You should return either true or false according to your logic.


Update
Version-1
Ok, so do two things.

1. Change function signature.
C#
public static bool send_mail(string toemailid)

Remove "static" from here.
So, it will be...
C#
public bool send_mail(string toemailid)

The static methods can only be called within its own class, not from other classes.

2. Put a break point in this function and see whether execution comes to this function, when you are sending mail.


Version-2
1.
Quote:
Error 2 The best overloaded method match for 'System.Net.Mail.MailMessage.MailMessage(System.Net.Mail.MailAddress, System.Net.Mail.MailAddress)' has some invalid arguments C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs 114 30 WebApplication1
Error 3 Argument 2: cannot convert from 'string' to 'System.Net.Mail.MailAddress' C:\Users\user\Desktop\WebApplication1\WebApplication1\connection.cs 114 52 WebApplication1

After writing like below
C#
MailMessage mm = new MailMessage(from, to);

the above errors will be fixed.

As MailMessage Class has constructors like below...(you can see there)

1. MailMessage Constructor (MailAddress, MailAddress)
where you should pass two MailAddress objects.

2. MailMessage Constructor (String, String)
where you should pass two strings.

3. MailMessage Constructor (String, String, String, String)
where you should pass four string.

-> Previously, you have written...
C#
MailMessage mm = new MailMessage(from, toemailid);

where from is a object of MailAddress Class, but toemailid was a string.


-> Now you have done correct like...
C#
MailMessage mm = new MailMessage(from, to);

where both from and to are objects of MailAddress Class.


Thanks...
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900