If transparency is 100% then on-click event will not work for div tag.
Monday, April 30, 2012
Sunday, March 25, 2012
Creating Oracle Schema to load data into ESRI ArcSDE
ESRI’s ArcSDE and Oracle Database combination can be tricky sometimes. Here are the steps to create an Oracle Schema and load data into ESRI’s ArcSDE. These steps should be performed after setting up ArcSDE software and running the post install and assuming that the default ArcSDE service is already running in port 5151.
First the Oracle Database and the user must be created. Next the proper permissions have to be provided.
Finally in ArcSDE we need to run the setup script then all is done.
CREATE TABLESPACE &1 DATAFILE 'D:\app\oracle\oradata\arcsde\&1..DBF' SIZE 500M AUTOEXTEND ON;
create user &1 identified by &2 default tablespace &1;
alter user &1 quota unlimited on &1;
GRANT CREATE SESSION,
CREATE TABLE,
CREATE TRIGGER,
CREATE SEQUENCE,
CREATE PROCEDURE,
CREATE INDEXTYPE,
CREATE LIBRARY,
CREATE OPERATOR,
CREATE PUBLIC SYNONYM,
CREATE TYPE,
CREATE VIEW,
DROP PUBLIC SYNONYM,
SELECT ANY TABLE,
ALTER ANY INDEX,
ALTER ANY TABLE,
ANALYZE ANY,
CREATE ANY INDEX,
CREATE ANY PROCEDURE,
CREATE ANY SEQUENCE,
CREATE ANY TRIGGER,
CREATE ANY VIEW,
DROP ANY INDEX,
DROP ANY PROCEDURE,
DROP ANY SEQUENCE,
DROP ANY TABLE,
DROP ANY VIEW,
EXECUTE ANY PROCEDURE,
SELECT ANY SEQUENCE,
ADMINISTER DATABASE TRIGGER
TO &1;
ECHO Setting Up %1 with password %2
sdesetup -o install -d ORACLE11G -i 5151:%1 -u %1 -p %2 -l %3.ECP
In ArcSDE, when making connection (assuming 5151 port is running default ArcSDE Service) make sure the connection is made to the correct schema not to the default SDE schema. Please check the snapshot below. In the sample "ECMV" is the Oracle Schema name which is also the username.
This was tested at ArcSDE 9.3 oracle 11g.
Good luck.
Cheers
Anand
First the Oracle Database and the user must be created. Next the proper permissions have to be provided.
Finally in ArcSDE we need to run the setup script then all is done.
The following script must be run in SQL Plus. Substitute ‘&1’ with username and ‘&2’ with password. This will create the database and provide proper permissions.
create user &1 identified by &2 default tablespace &1;
alter user &1 quota unlimited on &1;
GRANT CREATE SESSION,
CREATE TABLE,
CREATE TRIGGER,
CREATE SEQUENCE,
CREATE PROCEDURE,
CREATE INDEXTYPE,
CREATE LIBRARY,
CREATE OPERATOR,
CREATE PUBLIC SYNONYM,
CREATE TYPE,
CREATE VIEW,
DROP PUBLIC SYNONYM,
SELECT ANY TABLE,
ALTER ANY INDEX,
ALTER ANY TABLE,
ANALYZE ANY,
CREATE ANY INDEX,
CREATE ANY PROCEDURE,
CREATE ANY SEQUENCE,
CREATE ANY TRIGGER,
CREATE ANY VIEW,
DROP ANY INDEX,
DROP ANY PROCEDURE,
DROP ANY SEQUENCE,
DROP ANY TABLE,
DROP ANY VIEW,
EXECUTE ANY PROCEDURE,
SELECT ANY SEQUENCE,
ADMINISTER DATABASE TRIGGER
TO &1;
The following script must be run in DOS command prompt. Substitute ‘%1’ with username and ‘%2’ with password and ‘%3’ with ESRI EDN License File Name. This will setup ArcSDE and get it ready.
sdesetup -o install -d ORACLE11G -i 5151:%1 -u %1 -p %2 -l %3.ECP
In ArcSDE, when making connection (assuming 5151 port is running default ArcSDE Service) make sure the connection is made to the correct schema not to the default SDE schema. Please check the snapshot below. In the sample "ECMV" is the Oracle Schema name which is also the username.
This was tested at ArcSDE 9.3 oracle 11g.
Good luck.
Cheers
Anand
Saturday, February 25, 2012
Silverlight RIA Services - Records count mismatch
Team,
I was working with a Silverlight application which was fetching SQL data using RIA services. While coding I observed that the total number of records in the SQL data table is not matching with the records count in the Silverlight application.
After several debugging hours I found out a very crucial behavior.
All these tables that are coming in through RIA services need a primary key. If there is no primary key then the RIA services might try to pick a unique column on its own. But it’s always a hit and miss. So it’s better to make sure every table even every view that is being fetched through RIA services must have a “Unique Key Field”.
Hope this helps and saves time.
Happy Coding!
Cheers
Anand
I was working with a Silverlight application which was fetching SQL data using RIA services. While coding I observed that the total number of records in the SQL data table is not matching with the records count in the Silverlight application.
After several debugging hours I found out a very crucial behavior.
All these tables that are coming in through RIA services need a primary key. If there is no primary key then the RIA services might try to pick a unique column on its own. But it’s always a hit and miss. So it’s better to make sure every table even every view that is being fetched through RIA services must have a “Unique Key Field”.
Hope this helps and saves time.
Happy Coding!
Cheers
Anand
Thursday, February 23, 2012
Labeling in ArcIMS – Avoid Duplicate Labels when there is a JOIN
I came across a scenario where I am supposed to link the GIS features with external tables in ArcIMS. This was a one-to-many relationship, which means for one GIS feature there were many external records.
We want to label this GIS features, but when we tried labeling, it was showing duplicate labels, because of the one-to-many relationship established with the external records.
To control this we used the ArcIMS AXL syntax like shown below.
<SIMPLELABELRENDERER field= "AYED.env_field_sample_loc_point.LOCID" howmanylabels ="one_label_per_shape" labelbufferratio="3.0">
<TEXTSYMBOL antialiasing="true" font="Verdana" fontsize="8" glowing="255,255,255" interval="20"/>
</SIMPLELABELRENDERER>
Note down the tag “labelbufferratio”. This helps to remove those duplicate labels.
Monday, January 30, 2012
Updating ArcGIS FeatureLayer in Silverlight Application after performing a Query
There was a scenario where I need to display a Featurelayer in ArcGIS Silverlight Map Control and when the user performs a search on specific attributes (in this example date values), the Featurelayer records must be refreshed / updated on the Map Control.
The XAML file content is as follows. This featurelayer tag will be inside the MapControl.
<esri:FeatureLayer ID="Your Layer ID" Url="YourURL" Where="1=1" OutFields="All fields required for query seperated by comma." >
</esri:FeatureLayer>
This Button tag when clicked will invoke the Featurelayer Update Action. Note the use of Interaction Triggers.
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="buttonSearchDates" Content="Search Dates">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" PreviewInvoke="EventTrigger_PreviewInvoke">
<esri2009:UpdateFeatureLayerAction
FeatureLayerID="Your Layer ID"
TargetName="MapControl" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
Make sure the namespaces are declared properly like this.
xmlns:esri2009="http://schemas.esri.com/arcgis/client/2009"
xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
You also need references to these DLL files. You may need to download Microsoft Expression Blend SDK 4. This coding was done using Silverlight 4.
Microsoft.Expression.Interactions.dll
System.Windows.Interactivity.dll
In the csharp file these are the functions
private void EventTrigger_PreviewInvoke(object sender, System.Windows.Interactivity.PreviewInvokeEventArgs e)
{
PerformQuery(datePickerFrom.SelectedDate.Value, datePickerTo.SelectedDate.Value);
}
private void PerformQuery(DateTime startDate, DateTime endDate)
{
ESRI.ArcGIS.Client.FeatureLayer oFeatureLayer = MapControl.Layers["Your Layer ID"] as ESRI.ArcGIS.Client.FeatureLayer;
if (oFeatureLayer != null)
{
string whereClause = GetDateWhereClause(startDate, endDate);
oFeatureLayer.Where = whereClause;
oFeatureLayer.Refresh();
}
}
Hope this will help some programmer.
Cheers
Anand
The XAML file content is as follows. This featurelayer tag will be inside the MapControl.
<esri:FeatureLayer ID="Your Layer ID" Url="YourURL" Where="1=1" OutFields="All fields required for query seperated by comma." >
</esri:FeatureLayer>
This Button tag when clicked will invoke the Featurelayer Update Action. Note the use of Interaction Triggers.
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="buttonSearchDates" Content="Search Dates">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" PreviewInvoke="EventTrigger_PreviewInvoke">
<esri2009:UpdateFeatureLayerAction
FeatureLayerID="Your Layer ID"
TargetName="MapControl" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
Make sure the namespaces are declared properly like this.
xmlns:esri2009="http://schemas.esri.com/arcgis/client/2009"
xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
You also need references to these DLL files. You may need to download Microsoft Expression Blend SDK 4. This coding was done using Silverlight 4.
Microsoft.Expression.Interactions.dll
System.Windows.Interactivity.dll
In the csharp file these are the functions
private void EventTrigger_PreviewInvoke(object sender, System.Windows.Interactivity.PreviewInvokeEventArgs e)
{
PerformQuery(datePickerFrom.SelectedDate.Value, datePickerTo.SelectedDate.Value);
}
private void PerformQuery(DateTime startDate, DateTime endDate)
{
ESRI.ArcGIS.Client.FeatureLayer oFeatureLayer = MapControl.Layers["Your Layer ID"] as ESRI.ArcGIS.Client.FeatureLayer;
if (oFeatureLayer != null)
{
string whereClause = GetDateWhereClause(startDate, endDate);
oFeatureLayer.Where = whereClause;
oFeatureLayer.Refresh();
}
}
Hope this will help some programmer.
Cheers
Anand
Friday, December 30, 2011
Code for Zoom to GIS Layer
Team,
bool togoBool = false;
for (int layerIndex = 0; layerIndex < ArcMap.Document.ActiveView.FocusMap.LayerCount; layerIndex++)
{
ILayer2 eachLayer = ArcMap.Document.ActiveView.FocusMap.get_Layer(layerIndex) as ILayer2;
if (eachLayer is IFeatureLayer)
{
IFeatureLayer eachFeatureLayer = eachLayer as IFeatureLayer;
if (eachFeatureLayer.Name.Trim().ToUpper() == m_zoomtoLayerName.Trim().ToUpper())
{
IFeatureLayerDefinition featureLayerDef = eachFeatureLayer as IFeatureLayerDefinition;
QueryFilterClass queryFilter = new QueryFilterClass();
queryFilter.WhereClause = featureLayerDef.DefinitionExpression;
ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = eachFeatureLayer.FeatureClass.Search(queryFilter, true);
ESRI.ArcGIS.Geometry.IEnvelope envelopeCls = new EnvelopeClass();
envelopeCls.SetEmpty();
ESRI.ArcGIS.Geodatabase.IFeature feature;
while ((feature = featureCursor.NextFeature()) != null)
{
ESRI.ArcGIS.Geometry.IGeometry geometry = feature.Shape;
ESRI.ArcGIS.Geometry.IEnvelope featureExtent = geometry.Envelope;
envelopeCls.Union(featureExtent);
}
envelopeCls.Expand(m_zoomFactor, m_zoomFactor, true);
ArcMap.Document.ActiveView.Extent = envelopeCls.Envelope;
ArcMap.Document.ActiveView.Refresh();
return true;
} // if (eachFeatureLayer.Name.Trim().ToUpper() == gisLayerName.Trim().ToUpper())
} // if (eachLayer is IFeatureLayer)
} // for
return togoBool;
}
Here is the code to Zoom to a specific GIS Layer.
This code scans through all features and zooms to the extent of all.
Particularly this line of code "envelopeCls.Union(featureExtent);" collects the envelope extents of each record.
Have fun coding!
Cheers
Anand
private bool ZoomtoLayer(string m_zoomtoLayerName)
{bool togoBool = false;
for (int layerIndex = 0; layerIndex < ArcMap.Document.ActiveView.FocusMap.LayerCount; layerIndex++)
{
ILayer2 eachLayer = ArcMap.Document.ActiveView.FocusMap.get_Layer(layerIndex) as ILayer2;
if (eachLayer is IFeatureLayer)
{
IFeatureLayer eachFeatureLayer = eachLayer as IFeatureLayer;
if (eachFeatureLayer.Name.Trim().ToUpper() == m_zoomtoLayerName.Trim().ToUpper())
{
IFeatureLayerDefinition featureLayerDef = eachFeatureLayer as IFeatureLayerDefinition;
QueryFilterClass queryFilter = new QueryFilterClass();
queryFilter.WhereClause = featureLayerDef.DefinitionExpression;
ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = eachFeatureLayer.FeatureClass.Search(queryFilter, true);
ESRI.ArcGIS.Geometry.IEnvelope envelopeCls = new EnvelopeClass();
envelopeCls.SetEmpty();
ESRI.ArcGIS.Geodatabase.IFeature feature;
while ((feature = featureCursor.NextFeature()) != null)
{
ESRI.ArcGIS.Geometry.IGeometry geometry = feature.Shape;
ESRI.ArcGIS.Geometry.IEnvelope featureExtent = geometry.Envelope;
envelopeCls.Union(featureExtent);
}
envelopeCls.Expand(m_zoomFactor, m_zoomFactor, true);
ArcMap.Document.ActiveView.Extent = envelopeCls.Envelope;
ArcMap.Document.ActiveView.Refresh();
return true;
} // if (eachFeatureLayer.Name.Trim().ToUpper() == gisLayerName.Trim().ToUpper())
} // if (eachLayer is IFeatureLayer)
} // for
return togoBool;
}
Wednesday, November 30, 2011
Escaping XML
I found out about a neat function which can escape the XML content.
InnerXml = System.Security.SecurityElement.Escape(stringtoescape);
InnerXml = System.Security.SecurityElement.Escape(stringtoescape);
A simple inbuilt class like this can save you some time in trying to write your own function.
Tooltip in Windows Form Listbox Items
There was a request to provide tooltip for the items in the Listbox control.
The key idea is, selecting the listbox Index from the system point.
Here is the code.
Happy coding !
if (this.listBoxControl.SelectedIndex == -1)
{
TurnOffTooltip();
return;
}
if (sender is ListBox)
{
int selectedIndex = this.listBoxControl.SelectedIndex;
ListBox listBox = (ListBox)sender;
System.Drawing.Point point = new System.Drawing.Point(e.X, e.Y);
int hoverIndex = listBox.IndexFromPoint(point);
if (hoverIndex >= 0 && hoverIndex < listBox.Items.Count && hoverIndex == selectedIndex)
{
TurnOnTooltip();
}
else
{
TurnOffTooltip();
}
}
}
private void listBoxControl_MouseLeave(object sender, EventArgs e)
{
TurnOffTooltip();
}
private void TurnOffTooltip()
{
this.toolTip.SetToolTip(this.listBoxControl, "");
this.toolTip.Hide(this.listBoxControl);
return;
}
private void TurnOnTooltip()
{
SomeClass someClassObject = (SomeClass)this.listBoxControl.SelectedItem;
DisplayTooltip(someClassObject);
}
private void DisplayTooltip(SomeClass someClassObject)
{
string toDisplay = "Overlay Item : " + someClassObject.m_ILAOverlayItem.Name;
toDisplay = toDisplay + "\n" + "Impact Analysis Config : " + someClassObject.m_ILAimpactLayerConfig.ILConfigName;
toDisplay = toDisplay + "\n" + "GIS Layer : " + someClassObject.m_ILAimpactLayerConfig.GetGISLayerName();
toDisplay = toDisplay + "\n" + "Overlay Item : " + someClassObject.m_ILAOverlayItem.Name;
toDisplay = toDisplay + "\n" + "Inside Status Code : " + someClassObject.m_ILAInsideStatusCode[0].ToString();
toDisplay = toDisplay + "\n" + "Is Published : " + someClassObject.m_IsPublished.ToString();
this.toolTip.SetToolTip(this.listBoxControl, toDisplay);
this.toolTip.Show(toDisplay, this.listBoxControl);
}
private void listBoxControl_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.listBoxControl.SelectedItem != null)
{
SomeClass someClassObject = (SomeClass)this.listBoxControl.SelectedItem;
TurnOnTooltip();
}
}
The key idea is, selecting the listbox Index from the system point.
Here is the code.
Happy coding !
private void listBoxControl_MouseMove(object sender, MouseEventArgs e)
{if (this.listBoxControl.SelectedIndex == -1)
{
TurnOffTooltip();
return;
}
if (sender is ListBox)
{
int selectedIndex = this.listBoxControl.SelectedIndex;
ListBox listBox = (ListBox)sender;
System.Drawing.Point point = new System.Drawing.Point(e.X, e.Y);
int hoverIndex = listBox.IndexFromPoint(point);
if (hoverIndex >= 0 && hoverIndex < listBox.Items.Count && hoverIndex == selectedIndex)
{
TurnOnTooltip();
}
else
{
TurnOffTooltip();
}
}
}
private void listBoxControl_MouseLeave(object sender, EventArgs e)
{
TurnOffTooltip();
}
private void TurnOffTooltip()
{
this.toolTip.SetToolTip(this.listBoxControl, "");
this.toolTip.Hide(this.listBoxControl);
return;
}
private void TurnOnTooltip()
{
SomeClass someClassObject = (SomeClass)this.listBoxControl.SelectedItem;
DisplayTooltip(someClassObject);
}
private void DisplayTooltip(SomeClass someClassObject)
{
string toDisplay = "Overlay Item : " + someClassObject.m_ILAOverlayItem.Name;
toDisplay = toDisplay + "\n" + "Impact Analysis Config : " + someClassObject.m_ILAimpactLayerConfig.ILConfigName;
toDisplay = toDisplay + "\n" + "GIS Layer : " + someClassObject.m_ILAimpactLayerConfig.GetGISLayerName();
toDisplay = toDisplay + "\n" + "Overlay Item : " + someClassObject.m_ILAOverlayItem.Name;
toDisplay = toDisplay + "\n" + "Inside Status Code : " + someClassObject.m_ILAInsideStatusCode[0].ToString();
toDisplay = toDisplay + "\n" + "Is Published : " + someClassObject.m_IsPublished.ToString();
this.toolTip.SetToolTip(this.listBoxControl, toDisplay);
this.toolTip.Show(toDisplay, this.listBoxControl);
}
private void listBoxControl_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.listBoxControl.SelectedItem != null)
{
SomeClass someClassObject = (SomeClass)this.listBoxControl.SelectedItem;
TurnOnTooltip();
}
}
ArcIMS Error 1722 during installation
When installing ArcIMS, I got the following error.After some research I found the following solution
1. Goto Control Panel-> Services
2. Stop All ArcIMS /ArcGIS Services.
3. Stop Tomcat
4. Restart IIS.
Now install the ArcIMS Application /Service pack and the Error will not Repeat again.
Hope this saves some time for you.
Sunday, October 16, 2011
ASP.NET Master Page and Other Pages allignment Issues
I was creating a website with ASP.NET master page and other content pages.
For some reason when I was navigating from one page to another there was a shift in the footer. I had a horizontal line above the footer and this was jumping few pixels up and down when navigating through the pages.
After some research, I found out that this was happening because some of the pages had the paragraph (<p> </p>) tags and this was pushing the content a little bit.
I resolved this by adding a proper margin and padding to the div body in the master page itself.
Hope this tip can help you !
For some reason when I was navigating from one page to another there was a shift in the footer. I had a horizontal line above the footer and this was jumping few pixels up and down when navigating through the pages.
After some research, I found out that this was happening because some of the pages had the paragraph (<p> </p>) tags and this was pushing the content a little bit.
I resolved this by adding a proper margin and padding to the div body in the master page itself.
Hope this tip can help you !
Sunday, September 25, 2011
Class Deserializing issue with a class containing ArrayList as member variable
In one of my program, I had a class declared with a Member Variable whose datatype is ArrayList.
I serialized and saved the class contents in the text file.
When I tried to deserialize, I got back only the first value in the ArrayList, not all the values. Even though the file had more than 1 value, always I was getting back only one value into my class member variable.
After several debugging I thought of adding a constructor to the class and also inside that class constructor I initialized the ArrayList member variable to new ArrayList. After doing this then the deserialization happened properly. Then I got all my values back into my ArrayList member variable.
Whenever deserialization occurs the class constructor is called and proper initialization happens and then the ArrayList is being filled.
Hope this tip saves time for someone !
Wednesday, August 24, 2011
Creating hotspots on image
Team,
I was asked to create a simple web page with a static image and hotspots (hyperlinks which will navigate to other pages) on some of the image features.
Did some digging work and was able to write this code.
Here is the working link.
The link above contains two visible hotspots and one invisible hotspot.
Key points are :
1. The main DIV tag must contain the background image with style position relative.
2. The inner hyperlinks must contain style position absolute and you can place those hyperlinks wherever you want on the image.
I have added the source code below.
Happy coding !
Cheers
Anand
================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hotspot on Image</title>
</head>
<body style="text-align: center;">
<div id="divMain" style="background-image: url('sampleImage.png'); width: 528px;
height: 396px; position: relative;">
<a id="birdyahoo" href="http://www.yahoo.com" target="_blank" style="border: medium solid Red;
width: 46px; height: 75px; position: absolute; left: 186px; top: 81px;" title="Click here to visit Yahoo Website">
</a><a id="birdGoogle" href="http://www.google.com" target="_blank" style="border: medium solid Red;
width: 92px; height: 64px; position: absolute; left: 184px; top: 255px;" title="Click here to visit Google Website">
</a><a id="birdMicrosoft" href="http://www.microsoft.com" target="_blank" style="width: 69px; height: 38px; position: absolute; left: 347px; top: 162px;" title="Click here to visit Microsoft Website">
</a>
</div>
</body>
</html>
================
I was asked to create a simple web page with a static image and hotspots (hyperlinks which will navigate to other pages) on some of the image features.
Did some digging work and was able to write this code.
Here is the working link.
The link above contains two visible hotspots and one invisible hotspot.
Key points are :
1. The main DIV tag must contain the background image with style position relative.
2. The inner hyperlinks must contain style position absolute and you can place those hyperlinks wherever you want on the image.
I have added the source code below.
Happy coding !
Cheers
Anand
================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hotspot on Image</title>
</head>
<body style="text-align: center;">
<div id="divMain" style="background-image: url('sampleImage.png'); width: 528px;
height: 396px; position: relative;">
<a id="birdyahoo" href="http://www.yahoo.com" target="_blank" style="border: medium solid Red;
width: 46px; height: 75px; position: absolute; left: 186px; top: 81px;" title="Click here to visit Yahoo Website">
</a><a id="birdGoogle" href="http://www.google.com" target="_blank" style="border: medium solid Red;
width: 92px; height: 64px; position: absolute; left: 184px; top: 255px;" title="Click here to visit Google Website">
</a><a id="birdMicrosoft" href="http://www.microsoft.com" target="_blank" style="width: 69px; height: 38px; position: absolute; left: 347px; top: 162px;" title="Click here to visit Microsoft Website">
</a>
</div>
</body>
</html>
================
Sunday, July 24, 2011
Send E-Mail using ASP.NET
Team, I got involved in a project where we need to send e-mail from ASP.NET web application.
Tried many techniques and got all these errors .
" The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."
After few research here is the final working code.
bool togoValue = false;
try
{
MailMessage mm = new MailMessage();
mm.Sender = new MailAddress("fromEmailID@hotmail.com");
mm.From = new MailAddress("fromEmailID@hotmail.com ");
mm.To.Add(new MailAddress( "toEmailID@hotmail.com "));
mm.Subject = "This is test Subject";
mm.Body = "This is test Body";
SmtpClient client = new SmtpClient("smtp.live.com");
client.EnableSsl = true;
client.Send(mm);
togoValue = true;
}
catch (Exception ex)
{
throw new Exception("Error when sending mail." + ex.ToString());
}
return togoValue;
}
Replace your values in the right location and give it a try.
I tried both GMail server (smtp.gmail.com) and Hotmail Server (smtp.live.com) and both are working fine.
Have fun coding !
Tried many techniques and got all these errors .
"Mailbox unavailable. The server response was: DY-001 (SNT0-MC4-F22) Unfortunately, messages from 76.175.219.250 weren't sent. Please contact your Internet service provider. You can tell them that Hotmail does not relay dynamically-assigned IP ranges. You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors."
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first""Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated"
After few research here is the final working code.
public static bool SendMessage()
{bool togoValue = false;
try
{
MailMessage mm = new MailMessage();
mm.Sender = new MailAddress("fromEmailID@hotmail.com");
mm.From = new MailAddress("fromEmailID@hotmail.com ");
mm.To.Add(new MailAddress( "toEmailID@hotmail.com "));
mm.Subject = "This is test Subject";
mm.Body = "This is test Body";
SmtpClient client = new SmtpClient("smtp.live.com");
client.Credentials = new NetworkCredential("fromEmailID@hotmail.com", "password");
client.Port = 25;client.EnableSsl = true;
client.Send(mm);
togoValue = true;
}
catch (Exception ex)
{
throw new Exception("Error when sending mail." + ex.ToString());
}
return togoValue;
}
Replace your values in the right location and give it a try.
I tried both GMail server (smtp.gmail.com) and Hotmail Server (smtp.live.com) and both are working fine.
Have fun coding !
Subscribe to:
Posts (Atom)
All Blogs so far ...
-
►
2022
(1)
- ► March 2022 (1)
-
►
2021
(1)
- ► March 2021 (1)
-
►
2020
(1)
- ► October 2020 (1)
-
►
2019
(4)
- ► March 2019 (4)
-
►
2017
(7)
- ► November 2017 (5)
- ► February 2017 (1)
- ► January 2017 (1)
-
►
2016
(13)
- ► December 2016 (4)
- ► November 2016 (2)
- ► April 2016 (1)
- ► March 2016 (1)
- ► February 2016 (1)
- ► January 2016 (1)
-
►
2015
(12)
- ► December 2015 (1)
- ► November 2015 (1)
- ► October 2015 (1)
- ► September 2015 (1)
- ► August 2015 (1)
- ► April 2015 (1)
- ► March 2015 (1)
- ► February 2015 (1)
- ► January 2015 (1)
-
►
2014
(12)
- ► December 2014 (1)
- ► November 2014 (1)
- ► October 2014 (1)
- ► September 2014 (1)
- ► August 2014 (1)
- ► April 2014 (1)
- ► March 2014 (1)
- ► February 2014 (1)
- ► January 2014 (1)
-
►
2013
(12)
- ► December 2013 (1)
- ► November 2013 (1)
- ► October 2013 (1)
- ► September 2013 (1)
- ► August 2013 (1)
- ► April 2013 (1)
- ► March 2013 (1)
- ► February 2013 (1)
- ► January 2013 (1)
-
►
2012
(13)
- ► December 2012 (1)
- ► November 2012 (1)
- ► October 2012 (1)
- ► September 2012 (1)
- ► August 2012 (1)
- ► April 2012 (1)
- ► March 2012 (1)
- ► February 2012 (2)
- ► January 2012 (1)
-
►
2011
(16)
- ► December 2011 (1)
- ► November 2011 (3)
- ► October 2011 (1)
- ► September 2011 (1)
- ► August 2011 (1)
- ► April 2011 (2)
- ► March 2011 (1)
- ► February 2011 (2)
- ► January 2011 (1)
-
►
2010
(11)
- ► December 2010 (1)
- ► November 2010 (2)
- ► October 2010 (1)
- ► September 2010 (7)

