|
i have just did a copy and Paste from my old Function that does that when ever there is an Erro on my applicatin
private void Send_log()
{
String Client_Domain = System.Environment.MachineName.ToString();
Exception objErr = Server.GetLastError();
String FromE = ConfigurationManager.AppSettings.Get("FromE");
String To_1 = ConfigurationManager.AppSettings.Get("EmailTO1");
String To_2 = ConfigurationManager.AppSettings.Get("EmailTO2");
String Gmail_Password = ConfigurationManager.AppSettings.Get("Gmail_Password");
String Networked_Username = ConfigurationManager.AppSettings.Get("Networked_Username");
int Gmailport = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Gmailport"));
String Server_Host = Convert.ToString(ConfigurationManager.AppSettings.Get("GmailHost"));
String Body = Convert.ToString(Application["testError"]);
System.Environment.UserDomainName.ToString();
try
{
if (Body != "")
{
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(FromE);
mm.To.Add(new MailAddress(To_1));
mm.To.Add(new MailAddress(To_2));
mm.Subject = "Exception Report from " + Client_Domain + "In EXAM/CLASS";
mm.Body = Body;
mm.IsBodyHtml = true;
smtp.Host = Server_Host;
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = Networked_Username;
NetworkCred.Password = Gmail_Password;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = Gmailport;
smtp.Send(mm);
}
else
{
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(FromE);
mm.To.Add(new MailAddress(To_1));
mm.To.Add(new MailAddress(To_2));
mm.Subject = "Exception Report from " + Client_Domain + "In EXAM/CLASS";
mm.Body = "An Exception Occured, but it has not Been Realised.You can Wait for the Client to log a Fault";
mm.IsBodyHtml = true;
smtp.Host = Server_Host;
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = Networked_Username;
NetworkCred.Password = Gmail_Password;
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = Gmailport;
smtp.Send(mm);
}
}
catch (ApplicationException ex)
{
Response.Write(ex.Message);
}
}
as you can see the code, the values are comming from a webConfig, you can change them so that they come from your ASP.NET page.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi!
Can someone please tell me how I can retrieve the UserId from the aspnet_users table when I use the login tools in ASP.NET?
I am logging in as registered user and then when I click on edit profile I need the edit profile page to load with the UserId because I have made a one-to-one relationship between aspnet_users and Person table.
I am using a DataSet in a Seperate DAL. Basically I have configured the query to select record by UserId but I cannot get the correct GUID value from the aspnet_users table when going to editprofile page.
Thank you!!
Illegal Operation
|
|
|
|
|
u can get the UserId of any user via it's UserName. Firstly u can get the instance of MembershipUser then from this instance u will be able to get the Guid or UserId of that user. This same value is going to store in the aspnet_users table.
MembershipUser user = Membership.GetUser("UserName");
Guid userId = (Guid)user.ProviderUserKey;
You can get the UserName of the currently loggedin user via Context.User.Identity also.
|
|
|
|
|
Hi, everyone. The situation is, I am converting a tiff image file into byte[], then to stream then saving it as jpeg image format, then display it on browser, so that the jpeg opens in a picture viewer instead of webpage. The code works in IE 6 and firefox, but does not work in IE 7. In IE 7, the blank page appears and automatically closes. The code is as follows:-
System.IO.Stream _stream = new MemoryStream(byteArray);
Bitmap _bmp = new Bitmap(_stream);
Response.Clear();
Response.AddHeader("Content-Disposition","attachment;filename=adc.gif");
Response.ContentType = "image/gif";
_bmp.Save(Response.OutputStream, ImageFormat.Gif);
Response.End();
_bmp.Dispose();
_stream.Close();
This code is called in the page_load of a page in server a. Since the tiff image is located on a different server(server b) other than the web server, the image path is passed to web service located at server b, image is read and converted to byteArray and returned to server a. I guess the problem is with Content-Disposition.
Any help is appreciated.
|
|
|
|
|
Try this
============
byte[] message; // converting a tiff image file into byte[]
bool ret = false;
string filepath = "C:\";
if (Contentdisposition != null)
{
ret = Contentdisposition.StartsWith(" attachment;");
//code to decode the data
if (ret && (contentTransferEncoding.ToUpper().Equals("BASE64")))
{
//create the file and store the binart data
//store to test create the file with attachment name later
string[] filename = Contentdisposition.Split(';');
attachfile = filename[1];
attachfile = Regex.Replace(attachfile, "^[ | ]+filename=[\"]*([^\"]*).*$", "$1");
filepath+=attachfile;
m_binaryData = Convert.FromBase64String(message.Replace("\n", ""));
System.IO.BinaryWriter bw = new BinaryWriter(new FileStream(filepath, System.IO.FileMode.Create));
bw.Write(m_binaryData);
bw.Flush();
bw.Close();
}
}
|
|
|
|
|
I will begin by stating that I am NOT an ASP.NET developer. My new job now pushes me into it.
So with that said I'm trying to do the following:
This asp app is a single screen with the top 2/3 a bunch of dropdowns that the user selects to isolate a specific location.
Once that location is set, I need to dynamically add 4 - 6 legs which the user will provide the name for each leg.
I want to do this one leg at a time so I have a place holder named insertHere and a usercontrol with a lable, textbox, and button which says "Next Leg".
When I click the button Create Legs....my first leg control shows just fine. I enter a leg ID and click the Next Leg button (part of the control). My Next Leg process is this:
protected void NextEventHandler(object sender, EventArgs e)
{
if (NextEvent != null)
{
this.next.Visible = false;
NextEvent(sender, e);
}
}
The idea is to make the button invisible then fire the NextEvent up to the parent container. My NextEvent code is simple right now:
protected void HandleNextEvent(object sender, EventArgs e)
{
CreateLegsRequestHandler(sender, e);
}
What happens is this: when I click the button Next Leg, my entire control goes invisible and I do not see either the Leg One control or the Leg Two control being displayed. I'm puzzled and confused. Can the ASP.NET gods please help me with why it isn't working?
My desired result:
xxxxx dropdown
xxxxx dropdown
xxxxx dropdown
xxxxx dropdown [Create Legs]
(within PlaceHolder(insertHere).Controls)
Leg 1 textboxValue1 -invisible buttons-
Leg 2 textboxValue2 -invisible buttons-
Leg 3 textboxValue3 -invisible buttons-
Leg 4 _____________ [Next Leg] [Done]
|
|
|
|
|
Dynamic controls created like this will not have viewstate persisted. When you use dynamic controls, you need to recreate it on every postback.
Michael Eber wrote:
(within PlaceHolder(insertHere).Controls)
Leg 1 textboxValue1 -invisible buttons-
Leg 2 textboxValue2 -invisible buttons-
Leg 3 textboxValue3 -invisible buttons-
Leg 4 _____________ [Next Leg] [Done]
What you need here is to display tabular data. GridView will be the best control and it handles viewstate very well. To get your desired result, use a GridView with necessary columns. Use TemplateColumn to display text box and button. When Create Leg is clicked, add a new row to the GridView 's data source and rebind the gridview.
|
|
|
|
|
Okay...I've been tinkering with this so far and have a few questions....
First: I have a dropdown box and I defined an OnSelectedIndexChange event. When I run the application and I select an item in the dropdown box, my next dropdown box is not populated!
UIPDATE: I believe I got this fixed. Set the dropdowns to AutoPageBack (or something like that).
Second: When I add dropdown lists to the GridView do I also use a TemplateColumn?
Finally: I must be using the TemplateColumn incorrectly. If it is in the Gridview it complains no such type exists.
If I add a <Column> header then add the TemplateColumn I get a different error. Where to I add the TemplateColumn?
Do I use a <Field> header instead?
modified on Monday, September 28, 2009 12:57 PM
|
|
|
|
|
On my page I have a plain Gridview Control.
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
In the code behind, I populate a dataview and bind it to the Gridview.
Me.GridView1.DataSource = objSF.DV
Me.GridView1.DataBind()
This works fine.
Now I want to change the formatting of column(4) to be formatted as currency.
I've tried, CType(Me.GridView1.Columns(4), BoundField).DataFormatString = "{0:c" , in various Gridview events with no success;
in fact, it appears that everywhere I try the above code, the Grid reports that there are no columns at all !
I've used, System.Diagnostics.Debug.WriteLine(Me.GridView1.Columns.Count.ToString) in the following events and gotten zero as a result.
GridView1_RowCreated
GridView1_DataBound
GridView1_PreRender
GridView1_RowDataBound
What am I doing wrong ?
How can I format a column to display the data as currency ?
Regards,
David
|
|
|
|
|
From ASP.NET 2.0 everything is encoded using HTMLEncode which prevents any modification being done to the bound controls. Just use like this :
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField DataField="CurrencyField" HeaderText="Amount" DataFormatString="{0:c}" HtmlEncode="false" />
</Columns>
</asp:GridView>
You can see I placed HtmlEncode=false .. This is required for every BoundField in Gridview to reformat the data.
I am hoping this would work...
|
|
|
|
|
You can also covert it in Template Field then format the value as you want and bind to the control in RowDataBound Event.
|
|
|
|
|
Thank you for your input. For now, I have traced back where the dataset is populated and used the following to format the data.
SQLcmd.Parameters("@ORDERVALUE").Value = String.Format("{0,15:c}", dAmt)
This is OK for now.
|
|
|
|
|
Hey David
You have solved your problem this way but it's not the efficient way to work if u r working on project following n tier architecture and MVC design pattern. In that case the data service should return the data in most common/raw format and then presentation layers should convert them as per the requirement. So if have multiple views using the same data service can display the data as per their requirements. They are not bound to display the original one.
|
|
|
|
|
Very true about returning data in a common format and have the presentation layer handle the formatting. I'll remember that in future designs.
Btw: This report is not finished, so it may get scrapped completely. A meeting with management is scheduled for this morning.
|
|
|
|
|
Hi..
How can I change the alert messages title..
thanks
By:
Hemant Thaker
|
|
|
|
|
Hemant Thaker wrote: How can I change the alert messages title..
You Can't !
The only thing you can do, create your alert using DIV. Make it Float. Use Custom Header Title and Button
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hemant Thaker wrote: How can I change the alert messages title..
No, You can not!
You can instead use custom alert boxes (and there are already many available on internet), look for them...
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
|
|
Hi All,
I am getting 'sys' is undefined suddenly in one of the QA environemnt.
There are no code changes. it seems there is some environmental issue but not sure what is causing this issue.
I am saying there is no code issue as this code is working in other QA environment (present in other box)
a also checked the web.config it is same as in other environment too....
When checked with HTTP watch in the browser it seems that webresource.axd files are not getting downloaded
when it is trying to donwload the file server is giving 302 http error and redirecting to some error page
but for me page is redirecting properly with javascript error "sys is undefined"
Please let me know if any one has experienced the same issue
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|
|
|
Thanks for the reply Manas .. let me chek
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|
|
Still not working ...
so do you know why ScriptResource.axd requests return 302 in my case ? intead of 200
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|
|
Do you have ASP.NET CTP installed.
302 is returned when Request is temporarily removed from the server. I think in your case, the id associated with the ScriptResource.axd which downloads the specific file got whacked.
Can you paste the script src in the browser addressbar directly and check whether the file is downloaded properly or not...??
|
|
|
|
|
Not sure what went wrong .....
now its working as expected ....
thanks all
Thanks and Regards
Sandeep
If If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
Check My Blog
|
|
|
|