我正在尝试在sharepoint中搜索文件

时间:2016-11-22 10:56:17

标签: c# sharepoint

我使用的代码是:

List<ScenarioModel> result = new List<ScenarioModel>();

            string webUrl = "https://microsoft.sharepoint.com/teams/ABCD/EFGHI";

            string userName = System.Configuration.ConfigurationManager.AppSettings["userName"];

            SecureString password = ConvertToSecureString(System.Configuration.ConfigurationManager.AppSettings["userPassword"]);

            using (ClientContext ctx = new ClientContext(webUrl))
            {
                ctx.Credentials = new SharePointOnlineCredentials(userName, password);
                Web web = ctx.Web;
                ctx.Load(web);
                Microsoft.SharePoint.Client.List docList = web.Lists.GetByTitle("Documents");
                ctx.Load(docList);

                KeywordQuery keywordQuery = new KeywordQuery(ctx);
                keywordQuery.QueryText = queryText;

                SearchExecutor searchExecutor = new SearchExecutor(ctx);

                ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);

                ctx.ExecuteQuery();
                foreach (var resultRow in results.Value[0].ResultRows)
                {
                    ScenarioModel modelObject = new ScenarioModel();
                    modelObject.Path = resultRow["Path"];
                    modelObject.Title = resultRow["Title"].ToString();
                    result.Add(modelObject);
                }
            }

            return result;

现在这会返回正确的路径。当我点击网址时,系统会要求我下载一个便笺文件。有没有办法让我可以在线打开这个共享点文件而不是下载它?

1 个答案:

答案 0 :(得分:1)

我这样找到了

                            ctx.Load(item.File);
                        ctx.ExecuteQuery();
                        Console.WriteLine(item.File.LinkingUrl);

LikingUrl是你想要的。