Search This Blog

Wednesday, November 26, 2014

Could not load file or assembly 'AjaxControlToolkit, Version=1.0.10301.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' or one of its dependencies. Access Denied (Zugriff verweigert)

Review the permissions of the user that you're trying to impersonate.

In my situation, I was only getting the error on my development machine, rather than on our staging or deployment servers. (For while I got around this by removing the 'identity' node from web.config in my dev environment and just adding the line in post-build so it wasn't a problem anyone other than me.

Thursday, November 20, 2014

Migration from Visual Studio 2008 to 2013 : Website is not running (throwing access denied error)

Migration from Visual Studio 2008 to 2013

Without any code changes I successfully migrated from VS 2008 to 2013 but when running website from VS 2013 I got below error.

Server Error in '/' Application.
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408


Change the below settings to make everything works.

1. Goto Project properties (F4)
2. Update AnonymousAuthentication to Disabled
3. Update WindowsAuthentication to Enabled

Another way also u can change the settings
Go to "\My Documents\IISExpress\config\applicationhost.config" folder and update anonymousAuthentication to be false and the windowsAuthentication mode to true.

Wednesday, November 12, 2014

System.InvalidOperationException: The path / could not be assigned report viewer (Der Pfad / konnte nicht zugeordnet werden)

Report Viewer and (Vista x64 or Windows 7 64 bit)
I have the following problem:

1. Create a new website
2. Insert the reportviewer control.
3. Run the application. An error occurs. The same code runs under XP x86 with no problem, but does not work with Vista x64.

Source of the aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>



Untitled Page







This is the error message:


[InvalidOperationException: The path / cannot assigned.]
System.Web.Configuration.ProcessHostConfigUtils.MapPathActual(String siteName, VirtualPath path) +261
System.Web.Configuration.ProcessHostMapPath.MapPathCaching(String siteID, VirtualPath path) +580
System.Web.Configuration.ProcessHostMapPath.GetPathConfigFilenameWorker(String siteID, VirtualPath path, String& directory, String& baseName) +19
System.Web.Configuration.ProcessHostMapPath.System.Web.Configuration.IConfigMapPath.GetPathConfigFilename(String siteID, String path, String& directory, String& baseName) +37
System.Web.Configuration.HostingPreferredMapPath.GetPathConfigFilename(String siteID, String path, String& directory, String& baseName) +77
System.Web.Configuration.WebConfigurationHost.GetStreamName(String configPath) +166
System.Configuration.Internal.DelegatingConfigHost.GetStreamName(String configPath) +10
System.Configuration.BaseConfigurationRecord.InitConfigFromFile() +249

[ConfigurationErrorsException: Error during load of configuration file.: The path / cannot assigned.]
System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) +246879
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) +40
System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams) +412
System.Configuration.Internal.InternalConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(Type typeConfigHost, Object[] hostInitConfigurationParams) +29
System.Web.Configuration.WebConfigurationHost.OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, String site, String locationSubPath, String server, String userName, String password, IntPtr tokenHandle) +961
System.Web.Configuration.WebConfigurationManager.OpenWebConfigurationImpl(WebLevel webLevel, ConfigurationFileMap fileMap, String path, String site, String locationSubPath, String server, String userName, String password, IntPtr userToken) +84
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(String path) +36
Microsoft.Reporting.WebForms.ReportViewer.ConfigContainsHandler() +80
Microsoft.Reporting.WebForms.ReportViewer.OnInit(EventArgs e) +96
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7092
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) in c:\Users\fritz.MSE\AppData\Local\Temp\Temporary ASP.NET Files\website1\7d6f2e0f\c6b6426d\App_Web_9thttpm_.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +362
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64

Solution

You have to run as administrator due to UAC on Windows Vista/7

Wednesday, September 10, 2014

The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data, OledbException in c# .net

/*If you are facing issues with saving large data into excel
* u may get oledbexception like
* "The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data"
* below is the solution for insert and updation of data
*/
  private void btnSaveExcel_Click(object sender, EventArgs e)
{

  string path = @"C:\TEMP\Testing.xls";
oXL =
new Microsoft.Office.Interop.Excel.Application();oXL.Visible =
false;oXL.DisplayAlerts =
false;mWorkBook = oXL.Workbooks.Open(path, 0,
false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);


//Get all the sheets in the workbook mWorkSheets = mWorkBook.Worksheets;
//Get the sheet which was already existsmWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("FAS");Microsoft.Office.Interop.Excel.
Range range = mWSheet1.UsedRange;
int colCount = range.Columns.Count;
int rowCount = range.Rows.Count;mWSheet1.Cells[rowCount + 1, 1] = txtId.Text;
mWSheet1.Cells[rowCount + 1, 2] = txtName.Text;

mWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.
XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  //cleanup workbook and sheet
mWorkBook.Close(Missing.Value, Missing.Value, Missing.Value);mWSheet1 =
null;mWorkBook =
null;oXL.Quit();

GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}


private void btnUpdateExcel_Click(object sender, EventArgs e){

  string path = @"C:\TEMP\Testing.xls";
oXL =
new Microsoft.Office.Interop.Excel.Application();oXL.Visible =
false;oXL.DisplayAlerts =
false;mWorkBook = oXL.Workbooks.Open(path, 0,
false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
//Get all the sheets in the workbook mWorkSheets = mWorkBook.Worksheets;
//Get the sheet which was already existsmWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("FAS");Microsoft.Office.Interop.Excel.
Range range = mWSheet1.get_Range("A1").Find(txtId.Text);

if (range != null){

//assume unique records are available for column A1int rowCount = range.Rows.Row;mWSheet1.Cells[rowCount, 2] = txtName.Text;
}

mWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.
XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
  //cleanup workbook and sheet
mWorkBook.Close(Missing.Value, Missing.Value, Missing.Value);mWSheet1 =
null;mWorkBook =
null;oXL.Quit();

GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}

Monday, September 8, 2014

Select/Insert/Update Excel 2007 File using c# in .net

//insert data into excel sheet
private void btnSave_Click(object sender, EventArgs e)
{
using (OleDbConnection excelConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\TEMP\\Testing.xlsx;Extended Properties='Excel 8.0;HDR=YES;'"))
{
excelConnection.Open();

OleDbCommand command = new OleDbCommand("INSERT INTO [Sheet1$] ([Id],[Name]) VALUES(@value1, @value2)", excelConnection);
command.Connection = excelConnection;

command.Parameters.AddWithValue("@value1", txtId.Text);
command.Parameters.AddWithValue("@value2", txtName.Text);

command.ExecuteNonQuery();
}

btnGetData_Click(null, null);
}

//get data from excel sheet
private void btnGetData_Click(object sender, EventArgs e)
{
using (OleDbConnection excelConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\TEMP\\Testing.xlsx;Extended Properties='Excel 8.0;HDR=YES;'"))
{
excelConnection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("select Id, Name from [Sheet1$]", excelConnection);
DataSet ds= new DataSet();
adapter.Fill(ds);

dgvExcelData.DataSource = ds.Tables[0];
}
}

//update data of excel sheet
private void btnUpdate_Click(object sender, EventArgs e)
{
using (OleDbConnection excelConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\TEMP\\Testing.xlsx;Extended Properties='Excel 8.0;HDR=YES;'"))
{
excelConnection.Open();

string sqlQuery = "update [Sheet1$] set [Name] = '" + txtName.Text + "' where [Id] = " + txtId.Text;

OleDbCommand command = new OleDbCommand(sqlQuery, excelConnection);
command.Connection = excelConnection;


command.ExecuteNonQuery();
}
}



Note: If the "id" column is numeric:

If the "id" column in the sheet is of "General" type, the Sql statement is:

UPDATE [Sheet1$] SET Name ='Nameddd' WHERE id=1

If the "id" column in the sheet is of "Text" type, the Sql statement is
UPDATE [Sheet1$] SET Name ='Nameddd' WHERE id="1"

Friday, February 21, 2014

Confirmation box from code behind (server side) c# using modalpopup ajax control

Confirmation box from code behind c# using modalpopup ajax control

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConfirmPopUp.aspx.cs" Inherits="ConfirmPopUp" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=70);
            opacity: 0.7;
        }
       
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
    </asp:ScriptManager>
    <div>
        <asp:HiddenField ID="HiddenField1" runat="server" Value="2" />       
        <asp:Button ID="Button4" runat="server" Text="Validate and Open POPUP" OnClick="Button4_Click" /><br />
        <cc1:ModalPopupExtender id="ModalPopupExtender1" runat="server" targetcontrolid="Button1"
            popupcontrolid="PnlModal" backgroundcssclass="modalBackground">        </cc1:ModalPopupExtender>
        <asp:Button ID="Button1" runat="server" Text="Button" Style="visibility: hidden" />
        <asp:Panel ID="PnlModal" runat="server" Width="450px" style="display:none;                                                                    background-color: #ffffdd;
border-width: 3px;
border-style: solid;
border-color: Gray;
padding: 3px;
height:75px;
text-align:center; ">
            Are you sure want to Process?<br />
            <asp:Button ID="Button2" runat="server" Text="Yes" OnClick="Button2_Click" />
            <asp:Button ID="Button3" runat="server" Text="No" OnClick="Button3_Click" />
        </asp:Panel>
    </div>
    </form>
</body>
</html>


Code Behind:
using System;

public partial class ConfirmPopUp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        if (HiddenField1.Value == "2")
        {
            ModalPopupExtender1.Show();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {      
        //Your Processing code placed here       
        ModalPopupExtender1.Hide();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        ModalPopupExtender1.Hide();
    }
}

How To: Stop the ModalPopup Flicker
In above code PnlModal having the style="display:none;” to avoid flickering of confirmation box when page load happens
<asp:Panel ID="PnlModal" runat="server" Width="450px" style="display:none;”                                                                   

How To: Avoid “Object Required” javascript error from ScriptResource.axd when popup is shown
Don’t use PnlModal.Visible = false/true; from code behind to hide/show the popup, this is not required why because ModalPopupExtender will take care this behaviour.


Popular Posts