我需要在这里处理SPWeb吗?

时间:2010-12-17 10:54:07

标签: sharepoint spweb

protected void getNews()
{   
 using (SPWeb web = getWeb("InternalNews"))

            {
                fetchNewsFromWeb(ref dtNews,true,"English",new string[] { "Internal news page" },web,startDate,endDate,false,true);
            }

}
protected SPWeb getWeb(string contentTypeUrlKey)
{
    try
    {
        List<string> urls = CTUrlWrapper.GetContentTypeUrl(contentTypeUrlKey, this.Page.Request.Url.ToString());
        return SPContext.Current.Site.OpenWeb(urls[0].ToLowerInvariant().Replace(SPContext.Current.Site.Url.ToLowerInvariant(), "").TrimStart('/'));
    }
    catch
    {
        throw new Exception("Can not fetch value from CTUrl list, key: \"" + contentTypeUrlKey + "\"");
    }
}

我真的需要在fetchNewsFromWeb方法中处理网页吗?

  protected DataTable fetchNewsFromWeb(ref DataTable dtAllData, bool useCriticalField, string pageLanguage, string[] contentTypes, SPWeb web, DateTime? fromDate, DateTime? toDate, bool otherUnitNews, bool useHeaderPrefix)
    {

        SPSiteDataQuery sdq = GetQuery(useCriticalField);
        StringBuilder sbQuery = new StringBuilder();
        sbQuery.Append(getWhereClause(pageLanguage, fromDate, toDate, contentTypes, otherUnitNews));
        sbQuery.Append(getOrderByClause(useCriticalField));
        sdq.Query = sbQuery.ToString();

        try
        {

            DataTable foundItems = web.GetSiteData(sdq);              
            if (foundItems.Rows.Count > 0)
            {
                foreach (DataRow row in foundItems.Rows)
                {
                    try
                    {
                        object[] dtAlldataTemp = extractNewsFields(row, useHeaderPrefix);
                        dtAllData.Rows.Add(dtAlldataTemp);

                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
        catch (Exception ex)
        {
        }

        finally {web.Dispose();}// do we really need this here?

        return dtAllData;
    }

protected SPWeb getWeb(string contentTypeUrlKey)
    {
        try
        {
            List<string> urls = CTUrlWrapper.GetContentTypeUrl(contentTypeUrlKey, this.Page.Request.Url.ToString());
            return SPContext.Current.Site.OpenWeb(urls[0].ToLowerInvariant().Replace(SPContext.Current.Site.Url.ToLowerInvariant(), "").TrimStart('/'));
        }
        catch
        {
            throw new Exception("Can not fetch value from CTUrl list, key: \"" + contentTypeUrlKey + "\"");
        }
    }

4 个答案:

答案 0 :(得分:3)

不,你没有。

using将负责处理它。

答案 1 :(得分:2)

你问过SPDisposeCheck吗?

答案 2 :(得分:0)

这取决于getWeb函数如何返回SPWeb。

如果它只是一个SPContext.Current.Web - &gt;答案是否定的。

如果通过OpenWeb()调用打开一个新的Web返回它。答案是肯定的。

答案 3 :(得分:-1)

您是否可以通过参考文件传递网页并获取外部处理费用?