表单附件显示问题

原文:http://www.cnblogs.com/lrforever/archive/2010/02/10/1667129.html

关于sharepoint显示附件的问题:

1、在 Sharepoint Desinger里拷贝列表的DispForm.aspx.重命名为DispForm1.aspx;

2、在DispForm1.aspx添加该列表的数据视图;

3、在dvt_1.rowview XSL template添加附件的地方加上      <SharePoint:AttachmentsField ControlMode="Display" FieldName="Attachments" runat="server" Visible="true"/>

4、测试可以正常显示

but

如果在同一网站集的其他站点引用此列表,建立此列表的数据视图,采用同上的办法却会报错

System.InvalidOperationException: 对象的当前状态使该操作无效,实在搞不懂啥问题。

希望高手能现身,指点一下。多谢啦

 

  

 

2009年2月24日更新内容如下:

        上述的方法在跨站点的时候没法使用 ,但为了解决这个问题,采用了编写用户控件的方法。

代码如下

 

代码
复制代码
using Microsoft.SharePoint;
public partial class UCAttachment : System.Web.UI.UserControl {     protected void Page_Load( object sender, EventArgs e)     {         if ( ! this .IsPostBack)         {             try             {                 GetAttachment(); // 取得附件的方法             }             catch (Exception ex)             {                 Response.Write(ex);             }         }
    }    
private void GetAttachment()     {         int ID = 0 ; // 取得页面参数         string id = Request.QueryString[ " ID " ];         int .TryParse(id, out ID); // 转化为int型         if (ID == 0 )         {             Response.Write( " 无效ID " );         }         else         {             SPSite site = new SPSite( " http://x.x.x.x/ " );
            SPWeb Myweb
= site.OpenWeb( " myweb " );             SPList StartStepList = Myweb.Lists[ " mylist " ]; // 打开列表
            SPListItem StartStepItem
= StartStepList.Items.GetItemById(ID); // 取得当前信息条记录             SPAttachmentCollection attach = StartStepItem.Attachments; // 取得当前信息条的附件             if (attach.Count > 0 )             {                 Label1.Text = " 附件: " ;                 for ( int i = 0 ; i < attach.Count; i ++ )                 {                     String url = attach.UrlPrefix + attach[i];
                    ListItem li
= new ListItem(attach[i], url);
                    BulletedList1.Items.Add(li);                 }             }         }     } }
 

转载于:https://www.cnblogs.com/liubinurl/archive/2012/07/17/2595373.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值