2012年8月13日 星期一

Sharepoint BDC 外部清單 下載 Excel

好不容易在整理好 BDC 後才發現他無法使用內建的功能來下載清單到 EXCEL 中.上網找了很久都找到2007 的作法. 那些API 有很多都是已停用的(雖然有人試出來,但我沒有 :( )

好了.以下是這個程式碼

<%@ Assembly Name="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
<%@ Assembly Name="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
<%@ Assembly Name="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="Microsoft.BusinessData, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ WebHandler Language="C#" Class="ExcelDumper"  %>
using System;
using System.Web;
using System.Web.UI;
using System.Web.SessionState;
using System.Collections;
using System.Collections.Generic;
using Microsoft.SharePoint;

using Microsoft.BusinessData.MetadataModel.Collections;
using Microsoft.BusinessData.Infrastructure;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.SharePoint.Administration;
using System.Web;
using Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.Db;
public class ExcelDumper : IHttpHandler, IReadOnlySessionState
{
    public bool IsReusable
    {
        get { return false; }
    }
    public void ProcessRequest(HttpContext context)
    {
       
        //entityNS = "GW_BDCM_IP.IP_ALL";
        //string entityName = "ENT_IP_ALL_";/
        string siteURL = "http://spcenter/IP/";
        string entityNS = "GW_BDCM_IP.IP_ALL";// "<nameSpace>";
        string entityName = "ENT_IP_ALL";// "<entityName>";
        string methodInstanceName = "ReadList";//"<methodInstanceName>";
        string H_HTML = "", TB_HTML = "", B_HTML = "";
        bool firtLine = true;
        context.Response.ContentType = "application/vnd.ms-excel";
       
        //context.Response.ContentType =
        //header('Content-disposition: attachment; filename='.$q);
       
        if (context.Request["entityNS"] != null)
        {
            entityNS = context.Request["entityNS"];
        }
        if (context.Request["entityName"] != null)
        {
            entityName = context.Request["entityName"];
        }
        if (context.Request["methodInstanceName"] != null)
        {
            methodInstanceName = context.Request["methodInstanceName"];
        }
       
        using (SPSite site = new SPSite(SPContext.Current.Site.Url))
        {
            using (new Microsoft.SharePoint.SPServiceContextScope(
                SPServiceContext.GetContext(site)))
            {
                BdcService service = SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
                IMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);
                IEntity entity = catalog.GetEntity(entityNS, entityName);
                IMethodInstance imethInst = entity.GetMethodInstance(methodInstanceName, MethodInstanceType.Finder);
                IEntityInstanceEnumerator prodEntityInstanceEnumerator = entity.FindFiltered(imethInst.GetFilters(), entity.GetLobSystem().GetLobSystemInstances()[0].Value);
              
                context.Response.Headers.Add("Content-Disposition", "attachment; filename='Download.xls'");
               
                while (prodEntityInstanceEnumerator.MoveNext())
                {
                    IEntityInstance IE = prodEntityInstanceEnumerator.Current;
                    foreach (IField f in entity.GetFinderView(methodInstanceName).Fields)
                    {
                        if (firtLine)
                        {
                            H_HTML = string.Format("{0}<td>{1}</td>", H_HTML, f.DefaultDisplayName );
                        }
                        TB_HTML = string.Format("{0}<td>{1}</td>", TB_HTML, IE[f].ToString().Replace("\r\n", "<br style=\"mso-data-placement:same-cell;\" />"));
                    }
                    B_HTML = string.Format("{0}<tr>{1}</tr>", B_HTML, TB_HTML);
                    if (firtLine)
                    {
                        B_HTML = string.Format("<tr>{0}</tr>{1}", H_HTML, B_HTML);
                    }
                    TB_HTML = "";
                    firtLine = false;
                }
                B_HTML = string.Format("<table>{0}</table>", B_HTML);
                context.Response.Write(B_HTML);
            }
        }
    }
}

使用方式
1.將這個代碼 存到 C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS 目錄下. 並存成 .ashx 檔
2. 自己在網站中建立一個LINK 網址設為
 http://spcenter/IP/_layouts/excel02.ashx?entityNS=GW_BDCM_IP.IP_ALL&entityName=ENT_IP_ALL
參數內容自己看.

2012年8月8日 星期三

找不到網站設定的的 導覽功能 無法編輯上方工具的選單

Sharepoint 開啟 發佈功能 才可以看到導覽功能才進行編輯上方工具列
在網站動作->網站設定->網站動作->管理網站功能 啟動 發佈功能 就可以了.



BDC Model: Sharepoint VS2010 debug 時出現ERROR. Could not load the Web.config configuration file. Check the file for any malformed XML elements,

Could not load the Web.config configuration file. Check the file for any malformed XML elements ...
那是因為 本身site url 是 http://spcenter 可是我打成 http://spcenter.domain.com.tw (這個不是預設) 所以會出現這個錯誤. 把他改回 http:/spcenter 或是將 http://spcenter.domain.com.tw 改成預設就好了.

2012年8月6日 星期一

Sharepoint Web.config 修改成Debug and trace



修改 c:\INTEPUB\WWWROOT\WSS\Virtual XXXX\80\WEB.CONFIG

Find:

<system.web> …<customErrors mode=”On” />

Change To:
<system.web> …<customErrors mode=”Off” />
Find:
<SharePoint>
<SafeMode … CallStack=”false” … >
</SharePoint>
Change To:
<SharePoint>
<SafeMode … CallStack=”true” … >
</SharePoint>

Enable Debugging Mode: Set batch and debug to “true”
Find: <compilation batch=”false” debug=”false”>
Change To: <compilation batch=”true” debug=”true”>


並在WEB.CONFIG 檔中的SYSTEM.WEB 區段中加入下行的
<trace enabled=”true” pageOutput=”true”/>


您的備份來自不同版本的 Microsoft SharePoint Foundation,且不能還原至執行目前版本

那是因為 內容資料庫的版本不對. 你可以去 Sharepoint 管理中心去看.各個內容資料庫的版本狀態. 在管理中心->升級與移轉->檢閱資料庫狀態  中去看看有那些是需要升級的.
我這只看到 WSS_Content 這個資料庫需要升級.
所以 開始\Microsoft SharePoint 2010 Products\SharePoint 2010 管理命令介面 輸入以下指令

Upgrade-SPContentDatabase   -Identity  "WSS_Content"

便可升級 內容資料庫 到最新.

SharePoint Backup Restore 指令

備份Sharepoint
Stsadm –o backup –url http://spcenter –filename c:\backup.dat
還原到 PORT 8080 的子網站集合
Stsadm –o restore –url http://spcenter:8080 –filename c:\backup.dat –overwrite

2012年8月5日 星期日

修改 Sharepoint SQL Server 帳號之密碼後.在 IIS 中 Application pool 某几個 功能會自動停止

目前我發現是這几個的密碼沒更新到. 所以只要去進階設定重設相關的帳號密碼就可以了.

Hyper V Restore 後出現 信任工作站和網域失敗之間的關係

Hyper V snapshot restore 後, 萬一該台OS有加入domain 時會出現the trust relationship between this workstation and the primary domain failed

這是因為你 restore 的時間點超過了. 網域成員:最長電腦帳密碼有效期 30天. 所以我們只要在回復的電腦中去重新設定他的密碼就好了. 有几個方式

1.單一帳密重設

  可以用以下的指定去修復.

netdom resetpwd /s:server.company.lab /ud:na\domainAdminId /pd:password

netdom resetpwd /s:goodwill.com.tw /ud:myaccount01 /pd:1234
netdom resetpwd /s:goodwill.com.tw /ud:myaccount02 /pd:1234

2. 退出AD 再重新加入

如果不想一一的去修改.你可以選擇重新加入DOMAIN.(先退出AD,再加入, 然後重開機)

3.在事前先設定  網域成員:最長電腦帳戶密碼有效期  為一個較大的值.

 可以去本機群組原則設定中(DC 中的 gpedit.msc)  中的

電腦設定->Windows 設定->安全性設定->本機一原則->安全性選項-> 網域成員:最長電腦帳戶密碼有效期 30 天, 改成 360 天.[這個我有去改過可是一直沒時間去驗證]

以上..希望不會再忘了