コード例 #1
0
        public async Task Init()
        {
            var folderList = await App._instance.IO.GetLocalDataAsync <List <FolderItem> >(StaticString.FolderListFileName);

            var historyList = await App._instance.IO.GetLocalDataAsync <List <HistoryItem> >(StaticString.HistoryListFileName);

            FolderCollection.Clear();
            DisplayHistoryCollection.Clear();
            if (!folderList.IsNullOrEmpty())
            {
                folderList.ForEach(p => FolderCollection.Add(p));
            }
            else
            {
                var folderItem = new FolderItem(App._instance.App.GetLocalizationTextFromResource(LanguageName.Default), FeatherSymbol.Activity);
                FolderCollection.Add(folderItem);
                await SaveFolderList();
            }

            string lastSelectedFolderId = App._instance.App.GetLocalSetting(Settings.LastSelectFolderId, "");

            if (!FolderCollection.Any(p => p.Id == lastSelectedFolderId))
            {
                lastSelectedFolderId = FolderCollection.First().Id;
            }

            CurrentSelectedFolder = FolderCollection.Where(p => p.Id == lastSelectedFolderId).First();

            if (!historyList.IsNullOrEmpty())
            {
                AllHistoryList = historyList;
                historyList.Where(p => p.FolderId == lastSelectedFolderId).ToList().ForEach(p => DisplayHistoryCollection.Add(p));
                HistoryChanged?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #2
0
        static public String UploadToTeamSite(String localPath)
        {
            var siteUrl = ConfigurationManager.AppSettings["teamSiteUrl"];

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                string username = ConfigurationManager.AppSettings["username"];

                //decrypt password
                string base64Encoded = ConfigurationManager.AppSettings["password"];
                string password;
                byte[] data = System.Convert.FromBase64String(base64Encoded);
                password = System.Text.ASCIIEncoding.ASCII.GetString(data);

                NetworkCredential _myCredentials = new NetworkCredential(username, password);
                clientContext.Credentials = _myCredentials;
                clientContext.ExecuteQuery();

                var ServerVersion = clientContext.ServerLibraryVersion.Major;

                var site = clientContext.Site;
                var web  = clientContext.Site.RootWeb;

                clientContext.Load(web, w => w.ServerRelativeUrl);
                clientContext.ExecuteQuery();

                var serverRelativeUrl = clientContext.Site.RootWeb.ServerRelativeUrl;

                //Check and create folder
                string name = DateTime.Now.ToString("yyyy.MM.dd");
                Microsoft.SharePoint.Client.List list = clientContext.Web.Lists.GetByTitle("CookieCheckerResults");
                FolderCollection folders = list.RootFolder.Folders;
                clientContext.Load(list);
                clientContext.Load(folders);
                clientContext.ExecuteQuery();

                var folderExists = folders.Any(X => X.Name == name);
                if (!folderExists)
                {
                    Folder newFolder = folders.Add(name);
                    clientContext.Load(newFolder);
                    clientContext.ExecuteQuery();
                }

                //Add the file
                string[] Splits = localPath.Split('\\');
                using (FileStream fs = new FileStream(localPath, FileMode.Open))
                {
                    Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/sites/sp_team_nbg/CookieCheckerResults/" + name + "/" + Splits[Splits.Length - 1], fs, true);
                }

                return(ConfigurationManager.AppSettings["teamSiteUrl"] + "/CookieCheckerResults/" + name);
            }
        }