从子文件夹中获取所有文件

编程入门 行业动态 更新时间:2024-10-21 06:32:33
本文介绍了从子文件夹中获取所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用可视化Web部件.

I am using visual web part.

我正在尝试以编程方式获取子文件夹中上载的所有文件,并在超链接中显示每个文件.我已经尝试了以下代码,但不确定如何检索文件并将其添加到超链接.超链接是在aspx中创建的.

I am trying to fetch all the files uploaded in a sub folder programmatically and show each of the files in a hyperlink . I have tried the below code, but not sure, how to retrieve the file and add it to a hyperlink. The hyperlink is created in aspx.

private void ShowAttachmentLinks(SPWeb osubWeb) { SPQuery query = new SPQuery(); string foldername = "Shared Documents"; SPDocumentLibrary docLib = osubWeb.Lists[foldername] as SPDocumentLibrary; string SubFolderUrl = osubWeb.ServerRelativeUrl + "/" + foldername + "abc" + "/" + bcd; SPFolder folder = osubWeb.GetFolder(SubFolderUrl); query.Folder = folder; query.Query="<View Scope=\"RecursiveAll\">" + "<Where>" + "<Eq>" + "<FieldRef Name=\"FileDirRef\" />" + "<Value Type=\"Text\">" + folder +"</Value>" + "</Eq>" + "</Where>" + "</View>";

以上代码正确吗?如何检索每个文件?

Is the above code correct? How to retrieve each of the files?

谢谢

推荐答案

您好,Venkat,

Hi Venkat,

尝试以下代码:

public string CreateListUsingCAMLAttachments(string siteURL,string ID) { List list; string temp = null; IEnumerable<Microsoft.SharePoint.Client.ListItem> listItems; using (ClientContext context = new ClientContext(siteURL)) { list = context.Web.Lists.GetByTitle("CDP Tools"); CamlQuery cq = new CamlQuery(); cq.ViewXml = @"<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Text'>"+ID+"</Value></Eq></Where></Query><ViewFields><FieldRef Name='Attachments' /></ViewFields></View>"; listItems = context.LoadQuery(list.GetItems(cq)); context.Load(list.RootFolder); context.Load(list.RootFolder.Files); context.Load(list.RootFolder.Folders); context.ExecuteQuery(); foreach (Folder f in list.RootFolder.Folders) { context.Load(f.Folders); context.ExecuteQuery(); foreach (Folder f1 in f.Folders) { if (f1.Name == ID) { context.Load(f1.Files); context.ExecuteQuery(); foreach (File file1 in f1.Files) { ListBox1.Items.Add(file1.Name); temp = file1.Name; } } else { // } } } } return temp; }

C hange 代码作为您的要求.希望对您有所帮助.:)

Change code as your requirement.. Hope this will help.. :)

源 链接

Source Link

更多推荐

从子文件夹中获取所有文件

本文发布于:2023-11-09 21:06:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573434.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   从子   夹中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!