【发布时间】:2011-11-28 09:05:59
【问题描述】:
我使用gridview 从列表中动态选择列。这些列表也有一个附件字段。所以我在一个名为 attach 的变量中有附件文件 url。
例如:attach = "http: //sok:1234/Lists/CapabilityTableSales/attachments/1/Dashboard Solutions.pptx"
我使用了以下代码!!
private void PopulateGrid()
{
try
{
// List is Hard Coded here . we can also use current Context instead//
string SiteListURL = "http://sok:1234/Lists/Case%20Studies/";
using (SPSite oSiteCollection = new SPSite(SiteListURL))
{
using (SPWeb web = oSiteCollection.OpenWeb())
{
DataTable dt = new DataTable();
SPQuery query = new SPQuery();
query.Query = "";
if (txt_Search.Text != String.Empty)
{
txt_Search.Text = "Key1";
query.Query = @"<Where><Contains><FieldRef Name='Key%20words' /><Value Type='Text'>" + txt_Search.Text + "</Value></Contains></Where>";
}
query.ViewFields = String.Concat(
"<FieldRef Name='Title' />",
"<FieldRef Name='Key%20words' />",
"<FieldRef Name='Project%20Brief' />",
"<FieldRef Name='Execution%20Highlights' />");
query.ViewFieldsOnly = true;
SPList list = web.Lists["Case Studies"];
SPListItemCollection col = list.GetItems(query);
dt = web.Lists["Case Studies"].GetItems(query).GetDataTable();
dt.Columns.Add(new DataColumn("Attachment", typeof(HyperLink)));
foreach (DataRow drow in dt.Rows)
{
drow["Attachment"] = getURL(drow["Title"].ToString());
//Where the function getURL will return the attachment URL!! (Working Fine)
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
catch (Exception ex)
{
//throw ex;
}
}
如何在drow["Attachment"] = getURL(drow["Title"].ToString()); 行出现列不匹配错误
我的要求是在点击该 URL 时打开文件 (PPT)。
非常感谢!!
【问题讨论】:
标签: c# asp.net gridview sharepoint-2010 attachment