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"); } }
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"); if (folderPath.StartsWith( web.ServerRelativeUrl, StringComparison.OrdinalIgnoreCase ) ) { folderPath = folderPath.Substring(web.ServerRelativeUrl.Length); } 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 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); } }
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 }
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 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 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 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); } }