How to obtain the HttpContext in Event Handler

后端 未结 8 539
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 20:20

I’m trying to obtain the HTTPContext within an Event Handler in a Document Library in MOSS, but all I have is a null value of the HTTPContext.Current, I do the same thing on a L

8条回答
  •  生来不讨喜
    2021-01-22 20:48

    Step 1 Declare:

        private HttpContext currentContext;
        static HttpContext _stCurrentContext;
    

    Step 2

    currentContext = HttpContext.Current;      // in constructor
    

    Step3

    public override void ItemAdding(SPItemEventProperties properties)
                     _stCurrentContext = currentContext;
    

    Step 4

     public override void ItemAdded(SPItemEventProperties properties)
     if (_stCurrentContext.Request.Files[0].ContentLength > 0)
     HttpPostedFile uploadfile = _stCurrentContext.Request.Files[0];
    

提交回复
热议问题