0

I have a asp.net website which calculates average and standard deviation using custom timestamps query in the code behind and store results in excel file. But whenever I click to select the longer timeframe it shoots this error. Code behind is as follows :-

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
    Response.Clear()
    Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
    Response.Charset = ""
    Response.ContentType = "application/vnd.xls"
    Dim stringWrite As New System.IO.StringWriter()
    Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
    GridView6.RenderControl(htmlWrite)
    Response.Write(stringWrite.ToString())
    Response.[End]()
End Sub

Are there any changes required from the IIS point of view?

I have also added the following tag in the Web.config file but it is giving me the same error.

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
Snb93
  • 41
  • 2
  • 11
  • [Don't use `Response.End`](https://stackoverflow.com/questions/1087777/is-response-end-considered-harmful). – John Wu Jul 28 '17 at 21:32
  • @JohnWu Still same error removed `Response.End` – Snb93 Jul 28 '17 at 21:36
  • I don't understand your code, are you doing reading an excel file & binding to grid view. try to debug. – Arun Vinoth-Precog Tech - MVP Jul 30 '17 at 03:02
  • @ArunVinoth Yes basically I need to download an excel file using a button from the server – Snb93 Jul 30 '17 at 05:01
  • Error clearly saying that excel file is missing. Can you check the path of excel & put it in root folder of the application.. – Arun Vinoth-Precog Tech - MVP Jul 30 '17 at 05:12
  • @ArunVinoth I am not understanding your comment I don't have any specific path it goes by default in the downloads folder. For certain values the file doesn't download and shoots this error. – Snb93 Jul 30 '17 at 18:49
  • Are you deleting & recreating the file every time with the same name? Are you checking whether file is generated before trying to read it ? – Arun Vinoth-Precog Tech - MVP Jul 30 '17 at 20:16
  • @ArunVinoth The name is same the file doesn't generate since it gives error message for values of longer duration. – Snb93 Jul 30 '17 at 21:21
  • Hint: Your answer to my 2nd question in above comment will solve your issue. – Arun Vinoth-Precog Tech - MVP Jul 31 '17 at 00:21
  • @ArunVinoth Thanks for the hint appreciate it only thing I am confused about is why is it not generating files for longer duration values is there any way to overcome that. – Snb93 Jul 31 '17 at 04:09
  • What have you done for last 2 days? Did you improve your questions by **debugging** & posting relevant code then ? – Arun Vinoth-Precog Tech - MVP Jul 31 '17 at 12:46
  • @Arun Vinoth I was debugging the code it is generating files for lower value time stamps but for longer duration when I download the file after pressing the button it gives that error which I mentioned. Even tried changing the format to .csv but does not help either. – Snb93 Jul 31 '17 at 14:29

1 Answers1

0

In the web.config file added the following lines

 <configuration>
     <system.webServer>
      <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
    </security>
</system.webServer>
    </configuration>
Snb93
  • 41
  • 2
  • 11