I am trying to write an Ad Rotator component on my ASP.NET site,but keep running into an "interesting" problem. The routinestarts out by submitting the new ad information to the database(this part works fine), then attempts to write/append to astructured XML document (this is where it gets "interesting"). The system will attempt to write to the hard-coded XML documentand fail with the error message "Access to the path\"c:\\inetpub\\wwwroot\\H4\\Config\\AdRotator. Xml\" is denied.".However, the program will once again attempt the entire saveroutine (including writing to the DB, thereby duplicatingrecords), only this time it will write to the XML filecorrectly! Here is my code (in case it helps):
ASP.NET page
============
private void OKButton_Click(object sender, System.EventArgs e){
TheseAds.Business.Advertisement newAd = newTheseAds.Business.Advertisement();
newAd.ImageUrl = ImageURL.Text;
newAd.Description = Description.Text;
newAd.TrueNavigateUrl = NavigateURL.Text;
newAd.KeyWord = Keyword.Text;
newAd.AlternateText = AlternateText.Text;
newAd.CompanyID =Convert.ToInt32(CompaniesListBox.ItemsCompaniesLi stBox.SelectedIndex].Value);
newAd.Create();
Response.Redirect("Admin.aspx");
}
Business.Advertisement
======================
public void Create(){
HttpContext context = HttpContext.Current;
Configuration.ModuleSettings settings =Configuration.ModuleConfig.GetSettings();
Data.Advertisement newAd = newData.Advertisement(settings.ConnectionString);
newAd.Create(imageUrl, trueNavigateUrl, alternateText, keyword,companyId, description,
context.Server.MapPath(settings.RotatorXmlFile));
}
Data.Advertisement
==================
public void Create(string imageUrl, string trueNavigateUrl,string alternateText, string keyword, int companyId, stringdescription, string rotatorFile){
int rowsAffected;
SqlParameter[] parameters = { new SqlParameter("@companyID",SqlDbType.Int, 4),
new SqlParameter("@description", SqlDbType.VarChar, 255),
new SqlParameter("@trueNavigateUrl", SqlDbType.VarChar,255),
new SqlParameter("@adID", SqlDbType.Int, 4)};
parameters[0].Value = companyId;
parameters[1].Value = description;
parameters[2].Value = trueNavigateUrl;
parameters[3].Direction = ParameterDirection.Output;
RunProcedure("usp_Ads_CreateAdvertisement", parameters, outrowsAffected);
// now that the new ad is in the DB, put the rest of the detailsin the Rotator's XML file.
Configuration.ModuleSettings settings =Configuration.ModuleConfig.GetSettings();
XmlDocument rotatorDom = new XmlDocument();
rotatorDom.Load(rotatorFile);
XmlElement temp;
XmlElement newAd = rotatorDom.CreateElement("Ad");
temp = rotatorDom.CreateElement("ImageUrl");
temp.InnerText = imageUrl;
newAd.AppendChild(temp);
temp = rotatorDom.CreateElement("NavigateUrl");
temp.InnerText = settings.PassThroughPage + "?AD=" +parameters[3].Value.ToString();
newAd.AppendChild(temp);
temp = rotatorDom.CreateElement("AlternateText");
temp.InnerText = alternateText;
newAd.AppendChild(temp);
temp = rotatorDom.CreateElement("Keyword");
temp.InnerText = keyword;
newAd.AppendChild(temp);
temp = rotatorDom.CreateElement("Impressions");
temp.InnerText = "1";
newAd.AppendChild(temp);
rotatorDom.DocumentElement.AppendChild(newAd);
try{
rotatorDom.Save(rotatorFile);
}
catch(Exception ex){
throw new AppException(ex.Message);
}
}
Any help at all will be greatly appreciated.
--------------------------------
From: Chris McKenzie
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>1KviZ+ZSfUOdN9mCJJM5oQ==</Id>