This is a migrated thread and some comments may be shown as answers.

Export to CSV click of telerik Radgrid created completely programmatically rasies exception Path 'OPTIONS' is forbidden and PROPFIND is forbidden

6 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Surendra
Top achievements
Rank 1
Surendra asked on 27 May 2014, 12:07 PM
HI,
I have created RadGrid completely programmatically in Page_Init() method with Export to CSV button shown on the Grid. When i click on Export to CSV button is raising exception "Path 'OPTIONS' is forbidden" and some times PROPFIND is forbidden. I have even included in web.config file <add path="*" verb="OPTIONS, PROPFIND" type="System.Web.StaticFileHandler" /> still it gives the same excpetion. Please follow below code.

protected void Page_Init(object sender, EventArgs e)
{
_CurrentUser = (UserDetails)HttpContext.Current.Session["UserDetailSession"];

RadGrid RadGrid1 = new RadGrid();
RadGrid1.ID = "RadGrid1";
RadGrid1.AutoGenerateColumns = false;
RadGrid1.AllowPaging = true;
RadGrid1.AllowSorting = true;
RadGrid1.AllowFilteringByColumn = true;
RadGrid1.PageSize = 50;
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace;


RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);

GridEditCommandColumn EditColumn = new GridEditCommandColumn();
RadGrid1.MasterTableView.Columns.Add(EditColumn);
EditColumn.UniqueName = "Edit";

List<clsColumnList> listColumnList = null;
DynamicPopulation _objDynamic = new DynamicPopulation();

//please create few columns before usage of listColumnList
foreach (clsColumnList _clsColumnList in listColumnList)
{
GridTemplateColumn _TemplateColumn = new GridTemplateColumn();
_TemplateColumn.ItemTemplate = new ItemTemplate(_clsColumnList.COLUMN_NAME);
_TemplateColumn.EditItemTemplate = new EditItemTemplate(_clsColumnList.COLUMN_NAME, _clsColumnList.DISPLAY_NAME, ViewState["ColumnList"] as List<clsColumnList>, Convert.ToInt32(Session["CurrentMeneID"]));
_TemplateColumn.DataField = _clsColumnList.COLUMN_NAME;
_TemplateColumn.HeaderText = _clsColumnList.DISPLAY_NAME;
_TemplateColumn.UniqueName = _clsColumnList.COLUMN_NAME;

RadGrid1.MasterTableView.Columns.Add(_TemplateColumn);
}

GridButtonColumn DeleteColumn = new GridButtonColumn();
RadGrid1.MasterTableView.Columns.Add(DeleteColumn);
DeleteColumn.ButtonType = GridButtonColumnType.LinkButton;
DeleteColumn.CommandName = "Delete";
DeleteColumn.Text = "Delete";
DeleteColumn.UniqueName = "Edit";
DeleteColumn.HeaderText = "Delete";
DeleteColumn.ConfirmText = "Are you sure, you want to delete?";
RadPane2.Controls.Add(RadGrid1);

}

//Export to CSV button click event captured
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToCsvCommandName)
{
RadGrid RadGrid1 = sender as RadGrid;
//RadGrid1.ExportSettings.ExportOnlyData = true;
//RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.IgnorePaging = true;
RadGrid1.MasterTableView.GetColumn("Edit").Visible = false;
RadGrid1.MasterTableView.GetColumn("Delete").Visible = false;
///RadGrid1.Rebind();
RadGrid1.MasterTableView.ExportToExcel();
}
}

Please someone help me in this regard it would be greatly appreciated.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 May 2014, 04:38 AM
Hi Surendra,

Something's I noticed from your code is that, when generating a grid in the Page_Init event handler, grid columns should be added to the Columnscollection of the MasterTableView after their attributes are set. Another thing to change is that you are exporting to CSV and in ItemCommand you are calling ExportToExcel() instead of ExportToCSV() function. Please make the necessary changes. With the above code export is working fine at my end.

Thanks,
Shinu
0
Surendra
Top achievements
Rank 1
answered on 28 May 2014, 05:41 AM
Hi Shinu,
Thanks for your reply.
I think you might have missed looking at the code that i am actually adding Template columns at the end after all the properties are set. My Grid was already working fine as per expectation the only problem is with Export to CSV or Export to Excel. Even if i put ExportToCSV()  instead of ExportToExcel() it does not make any difference, it still giving me the same excetion "Path 'OPTIONS' is forbidden" and some times PROPFIND is forbidden.

Thanks
Surendra Kumar
0
Shinu
Top achievements
Rank 2
answered on 30 May 2014, 05:07 AM
Hi Surendra,

Unfortunately I'm not able to replicate this issue at my end.

Thanks,
Shinu
0
Kostadin
Telerik team
answered on 30 May 2014, 07:48 AM
Hello Surendra,

I am afraid I am also not able to replicate the issue which you are facing, but you could try adding the following code in your web.config file and let me know whether the issue is resolved.
<httpHandlers>
  <add verb="*" path="*.xls" type="System.Web.StaticFileHandler" />
</httpHandlers>
Additionally please keep in mind that it is not necessary to call ExportToCsv() method on ItemCommand event handler because when you click the export button the method will be fired automatically.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Surendra
Top achievements
Rank 1
answered on 30 May 2014, 08:09 AM
Hi Kostadin,
Thanks for your reply,
The httpHandler mentioned by you is already placed in the web.config file even i have added <add verb="*" path="*.csv" type="System.Web.StaticFileHandler" validate="true" /> also still no luck. I could not able to put entire code due to client data protection but i followed this telerik article http://www.telerik.com/help/aspnet-ajax/grid-custom-edit-forms.html
which is mentioned at the end of page. Please follow it once and let me know if you find any solution.

Thanks
Surendra Kumar P



 
0
Kostadin
Telerik team
answered on 04 Jun 2014, 06:36 AM
Hello Surendra,

The help article which you have provided is related with data editing. I am not sure how the editing is related with the export to CSV. Could you please provide more details what exactly I should try on my end?

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Surendra
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Surendra
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or