locked
global.ascx code not working RRS feed

  • Question

  • User-1668014665 posted
    <%@ Application Language="VB" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.IO.Compression" %>
    
        Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application shutdown
            Dim files2 As String() = System.IO.Directory.GetFiles(Server.MapPath("~/Members"), "*.xls")
            For Each file2 As String In files2
                System.IO.File.Delete(file2)
            Next
        End Sub


    Running code from my localhost windows xp asp.net 2.0 ajax project, this code is supposed to clear all xls files in the members directory. When I run view browser, and close project ( via browser X), this code does not run..any ideas???? 

    Tuesday, September 22, 2009 4:49 AM

Answers

  • User-1659704165 posted

    Hi,

    Global.asax is ile in which u should Sritw code what u have written not in .ascx file..

    http://msdn.microsoft.com/en-us/library/2027ewzw.aspx

    .ascx file is file for user control

    http://www.netomatix.com/development/usercontrols1.aspx

    the above link help u write and understding of .ascx file

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 22, 2009 5:00 AM
  • User-1548505211 posted

    One solution I can think of is writing a custom http module and add you cleanup code on session_end or application_end event. I have not tried this myself.

    A link below would guide you for custom httpmodule.

     

     http://msdn.microsoft.com/en-us/library/ms227673(VS.80).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 23, 2009 12:32 AM

All replies

  • User-1659704165 posted

    Hi,

    Global.asax is ile in which u should Sritw code what u have written not in .ascx file..

    http://msdn.microsoft.com/en-us/library/2027ewzw.aspx

    .ascx file is file for user control

    http://www.netomatix.com/development/usercontrols1.aspx

    the above link help u write and understding of .ascx file

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 22, 2009 5:00 AM
  • User-1548505211 posted

    The code is working, but you are doing an incorrect thing inside the Application_End event.  (If you refer to your event log, you can easily figure this out)

    You cannot call the Server.MapPath method in the Application_OnEnd script

    Refer to this link http://msdn.microsoft.com/en-us/library/ms524858.aspx  for more details.

     

    =======================

    Mark as an answer if this helps

    ======================

    Tuesday, September 22, 2009 5:18 AM
  • User-1668014665 posted

     Thanks,  so were can I run code at the end of a user session to delete unwanted files, generated by that user  ???

    Tuesday, September 22, 2009 12:20 PM
  • User-1548505211 posted

    One solution I can think of is writing a custom http module and add you cleanup code on session_end or application_end event. I have not tried this myself.

    A link below would guide you for custom httpmodule.

     

     http://msdn.microsoft.com/en-us/library/ms227673(VS.80).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 23, 2009 12:32 AM
  • User151468730 posted

    I suggest you using a System.Timers.Timer to do the work periodically. And the timer can be started in Application_Start method of global.ascx

    Tuesday, September 29, 2009 8:02 AM
  • User-1668014665 posted

     Ok, but can I user server path function in the "Application_Start" part of the global page within Asp.net 2.0 ???

    Tuesday, September 29, 2009 2:03 PM
  • User151468730 posted

    Yes,  you can call the "Server. Mappath" method in the "Application_Start" part.

    Tuesday, September 29, 2009 10:36 PM