public void SharePointConnectorGetFileBytes1Test() { SharePointConnector spConnector = new SharePointConnector(TestCommon.CreateClientContext(), TestCommon.DevSiteUrl, testContainer); using (var bytes = spConnector.GetFileStream("office365.png")) { Assert.IsTrue(bytes.Length > 0); } using (var bytes2 = spConnector.GetFileStream("Idonotexist.xml")) { Assert.IsNull(bytes2); } }
internal void PersistFile(Web web, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope, string folderPath, string fileName, Boolean decodeFileName = false) { if (creationInfo.FileConnector != null) { SharePointConnector connector = new SharePointConnector(web.Context, web.Url, "dummy"); Uri u = new Uri(web.Url); if (folderPath.IndexOf(u.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1) { folderPath = folderPath.Replace(u.PathAndQuery, ""); } using (Stream s = connector.GetFileStream(fileName, folderPath)) { if (s != null) { creationInfo.FileConnector.SaveFileStream(decodeFileName ? HttpUtility.UrlDecode(fileName) : fileName, s); } } } else { WriteWarning("No connector present to persist homepage.", ProvisioningMessageType.Error); scope.LogError("No connector present to persist homepage"); } }
public void SharePointConnectorSaveStream3Test() { // first save SharePointConnector spConnector = new SharePointConnector(TestCommon.CreateClientContext(), TestCommon.DevSiteUrl, testContainer); using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { spConnector.SaveFileStream("blabla.png", String.Format("{0}/sub1/sub11", testContainerSecure), fileStream); } // overwrite file long byteCount = 0; using (var fileStream = System.IO.File.OpenRead(@".\resources\custombg.jpg")) { byteCount = fileStream.Length; spConnector.SaveFileStream("blabla.png", String.Format("{0}/sub1/sub11", testContainerSecure), fileStream); } //read the file using (var bytes = spConnector.GetFileStream("blabla.png", String.Format("{0}/sub1/sub11", testContainerSecure))) { Assert.IsTrue(byteCount == bytes.Length); } // file will be deleted at end of test }
public void SharePointConnectorGetFileBytes2Test() { SharePointConnector spConnector = new SharePointConnector(); spConnector.Parameters.Add(AzureStorageConnector.CONNECTIONSTRING, TestCommon.DevSiteUrl); spConnector.Parameters.Add(AzureStorageConnector.CONTAINER, testContainerSecure); spConnector.Parameters.Add(SharePointConnector.CLIENTCONTEXT, TestCommon.CreateClientContext()); using (var bytes = spConnector.GetFileStream("custombg.jpg", String.Format("{0}/sub1", testContainerSecure))) { Assert.IsTrue(bytes.Length > 0); } string file2 = spConnector.GetFile("Idonotexist.xml", String.Format("{0}/sub1", testContainerSecure)); Assert.IsNull(file2); }
public void SharePointConnectorSaveStream1Test() { SharePointConnector spConnector = new SharePointConnector(TestCommon.CreateClientContext(), TestCommon.DevSiteUrl, testContainer); long byteCount = 0; using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { byteCount = fileStream.Length; spConnector.SaveFileStream("blabla.png", fileStream); } //read the file using (var bytes = spConnector.GetFileStream("blabla.png")) { Assert.IsTrue(byteCount == bytes.Length); } // file will be deleted at end of test }
public void SharePointConnectorDelete2Test() { SharePointConnector spConnector = new SharePointConnector(TestCommon.CreateClientContext(), TestCommon.DevSiteUrl, testContainer); // upload file using (var fileStream = System.IO.File.OpenRead(@".\resources\office365.png")) { spConnector.SaveFileStream("blabla.png", String.Format("{0}/sub1/sub11", testContainerSecure), fileStream); } // delete the file spConnector.DeleteFile("blabla.png", String.Format("{0}/sub1/sub11", testContainerSecure)); // read the file using (var bytes = spConnector.GetFileStream("blabla.png", String.Format("{0}/sub1/sub11", testContainerSecure))) { Assert.IsNull(bytes); } // file will be deleted at end of test }
private void PersistFile(Web web, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope, string folderPath, string fileName) { if (creationInfo.FileConnector != null) { var fileConnector = creationInfo.FileConnector; SharePointConnector connector = new SharePointConnector(web.Context, web.Url, "dummy"); Uri u = new Uri(web.Url); if (u.PathAndQuery != "/") { if (folderPath.IndexOf(u.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1) { folderPath = folderPath.Replace(u.PathAndQuery, ""); } } folderPath = HttpUtility.UrlDecode(folderPath); String container = HttpUtility.UrlDecode(folderPath).Trim('/').Replace("/", "\\"); String persistenceFileName = HttpUtility.UrlDecode(fileName); if (fileConnector.Parameters.ContainsKey(FileConnectorBase.CONTAINER)) { container = string.Concat(fileConnector.GetContainer(), container); } using (Stream s = connector.GetFileStream(persistenceFileName, folderPath)) { if (s != null) { creationInfo.FileConnector.SaveFileStream( persistenceFileName, container, s); } } } else { scope.LogError($"No connector present to persist {fileName}."); } }
public void SharePointConnectorDeleteFromWebRootFolder() { SharePointConnector spConnector = new SharePointConnector(); spConnector.Parameters.Add(SharePointConnector.CONNECTIONSTRING, TestCommon.DevSiteUrl); spConnector.Parameters.Add(SharePointConnector.CLIENTCONTEXT, TestCommon.CreateClientContext()); // upload file using (var fileStream = System.IO.File.OpenRead(@".\resources\testdefault.aspx")) { spConnector.SaveFileStream("blabla.aspx", string.Empty, fileStream); } // delete the file spConnector.DeleteFile("blabla.aspx"); // read the file using (var bytes = spConnector.GetFileStream("blabla.aspx")) { Assert.IsNull(bytes); } }
private void PersistFile(Web web, ProvisioningTemplateCreationInformation creationInfo, string folderPath, string fileName, Boolean decodeFileName = false) { try { if (creationInfo.FileConnector != null) { SharePointConnector connector = new SharePointConnector(web.Context, web.Url, "dummy"); Uri u = new Uri(web.Url); if (folderPath.IndexOf(u.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1) { folderPath = folderPath.Replace(u.PathAndQuery, ""); } String container = folderPath.Trim('/').Replace("%20", " ").Replace("/", "\\"); String persistenceFileName = (decodeFileName ? HttpUtility.UrlDecode(fileName) : fileName).Replace("%20", " "); using (Stream s = connector.GetFileStream(fileName, folderPath)) { if (s != null) { creationInfo.FileConnector.SaveFileStream( persistenceFileName, container, s); } } } else { Console.WriteLine("No connector present to persist homepage.", ProvisioningMessageType.Error); Console.WriteLine("No connector present to persist homepage"); } } catch (Exception ex) { throw ex; } }
internal void PersistFile(Web web, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope, string folderPath, string fileName, Boolean decodeFileName = false) { if (creationInfo.FileConnector != null) { var fileConnector = creationInfo.FileConnector; SharePointConnector connector = new SharePointConnector(web.Context, web.Url, "dummy"); Uri u = new Uri(web.Url); if (u.PathAndQuery != "/") { if (folderPath.IndexOf(u.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1) { folderPath = folderPath.Replace(u.PathAndQuery, ""); } } String container = folderPath.Trim('/').Replace("%20", " ").Replace("/", "\\"); String persistenceFileName = (decodeFileName ? Uri.UnescapeDataString(fileName) : fileName).Replace("%20", " "); if (fileConnector.Parameters.ContainsKey(FileConnectorBase.CONTAINER)) { container = string.Concat(fileConnector.GetContainer(), container); } using (Stream s = connector.GetFileStream(fileName, folderPath)) { if (s != null) { creationInfo.FileConnector.SaveFileStream( persistenceFileName, container, s); } } } else { WriteMessage($"No connector present to persist {fileName}.", ProvisioningMessageType.Error); scope.LogError($"No connector present to persist {fileName}."); } }