The following lines of code changes the appSetting section "DEFAULT_LANGUAGE" and
refreshes the current page (causes re-load of the entire web as we modify the Web.config)
using System.Web.Configuration;
using System.Configuration;
private AppSettingsSection section;
protected void btnSave_Click(object sender, EventArgs e)
{
Configuration config= WebConfigurationManager.OpenWebConfiguration("~");
section = (AppSettingsSection)config.GetSection("appSettings");
section.Settings["DEFAULT_LANGUAGE"].Value ="some language";
config.Save();
Response.Redirect(Request.Url.ToString());
}
For windows applications code is listed below.
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Happy Coding...!
samitha
adsense
Monday, November 9, 2009
Thursday, November 5, 2009
Report Viewer Export to PDF
You can use this as a common method to create reports. Here a dynamic pdf will be generated with the time ticks
//using
using Microsoft.Reporting.WebForms;
public static void GenerateReport(string repName,ref ReportViewer rv)
{
string mimeType;
string encoding;
string fileNameExtension;
Warning[] warnings;
string[] streamids;
byte[] exportBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = mimeType;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename="+repName+ DateTime.Now.TimeOfDay.Ticks.ToString() + "." + fileNameExtension);
HttpContext.Current.Response.BinaryWrite(exportBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
//using
using Microsoft.Reporting.WebForms;
public static void GenerateReport(string repName,ref ReportViewer rv)
{
string mimeType;
string encoding;
string fileNameExtension;
Warning[] warnings;
string[] streamids;
byte[] exportBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = mimeType;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename="+repName+ DateTime.Now.TimeOfDay.Ticks.ToString() + "." + fileNameExtension);
HttpContext.Current.Response.BinaryWrite(exportBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
Tuesday, November 3, 2009
ASP Net - 'PageMethods' is undefined
For this make sure you have following things set
1)PageMethods must be exposed with the public access modifier and static.
E.g.
[WebMethod]
public static bool foo
2)Set EnablePageMethods="true" on your ScriptManager.
1)PageMethods must be exposed with the public access modifier and static.
E.g.
[WebMethod]
public static bool foo
2)Set EnablePageMethods="true" on your ScriptManager.
Friday, October 30, 2009
'Error Creating Control' ... 'true' could not be set on property
“Error creating control – [text] could not be set on property” with custom ASP.NET server controls in VS 2008 SP1
have you ever got an AJAX control error like this. I have found the same bug as of today. I have wasted almost a 2-3 hours of development before googling “could not be set on property”. simple solution is colse the VS and open the project again. seems this is bug with AJAX.
solution
1) Removing the AjaxControlLibrary.dll file from solution (and on disk), and deleting all ajax toolboxes
2) adding the AjaxControlLibrary project directly into solution.
3) close .Net, reopen and load
Also dot forget to read this KB article
http://code.msdn.microsoft.com/KB961847
have you ever got an AJAX control error like this. I have found the same bug as of today. I have wasted almost a 2-3 hours of development before googling “could not be set on property”. simple solution is colse the VS and open the project again. seems this is bug with AJAX.
solution
1) Removing the AjaxControlLibrary.dll file from solution (and on disk), and deleting all ajax toolboxes
2) adding the AjaxControlLibrary project directly into solution.
3) close .Net, reopen and load
Also dot forget to read this KB article
http://code.msdn.microsoft.com/KB961847
Report Viewer Control missing Header Icons
Hi,
I have came accross this issue in IIS 7. You may have to configure in other IIS versions differently. Here is what I ve found.
In IIS 7, we need to make sure we configurate the ReportViewer handler.
You can follow these steps:
- Open Internet Information Services (IIS) Manager and select your Web application.
Under IIS area, double-click on Handler Mappings icon.
At the Action pane on your right, click on Add Managed Handler.
At the Add Managed Handler dialog, enter the following:- Request path: Reserved.ReportViewerWebControl.axd
- Type:
Microsoft.Reporting.WebForms.HttpHandler
Name:
Reserved-ReportViewerWebControl-axd
Click OK.
Add references to
Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.WebForms.dll
Microsoft.ReportViewer.ProcessingObjectModel.dll
in your project
and thats it
cheers
Subscribe to:
Posts (Atom)