本文整理汇总了C#中System.IO.File.GetBinary方法的典型用法代码示例。如果您正苦于以下问题:C# File.GetBinary方法的具体用法?C# File.GetBinary怎么用?C# File.GetBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.File
的用法示例。
在下文中一共展示了File.GetBinary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSandbox
public static void CreateSandbox(TestContext testContext)
{
var site = Node.Load<Site>("/Root/TestSiteForAppModelTest");
if (site == null)
{
site = new Site(Repository.Root);
site.Name = "TestSiteForAppModelTest";
var urlList = new Dictionary<string, string>();
urlList.Add("testhost", "Windows");
site.UrlList = urlList;
site.Save();
}
var homePage = EnsureSiteStartPage(site);
var webContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/WebContent1");
if (webContent == null)
{
webContent = new GenericContent(homePage, "WebContent");
webContent.Name = "WebContent1";
webContent.Save();
}
var file = Node.Load<File>("/Root/TestSiteForAppModelTest/Home/File1");
if (file == null)
{
file = new File(homePage);
file.Name = "File1";
file.GetBinary("Binary").SetStream(Tools.GetStreamFromString("File1 content"));
file.Save();
}
//---- Appmodel
var siteAppsFolder = Node.Load<SystemFolder>("/Root/TestSiteForAppModelTest/(apps)");
if (siteAppsFolder == null)
{
siteAppsFolder = new SystemFolder(site);
siteAppsFolder.Name = "(apps)";
siteAppsFolder.Save();
}
var siteAppsPageFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/Page");
if (siteAppsPageFolder == null)
{
siteAppsPageFolder = new SystemFolder(siteAppsFolder);
siteAppsPageFolder.Name = "Page";
siteAppsPageFolder.Save();
}
var siteAppsPageBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Browse");
if (siteAppsPageBrowsePage == null)
{
siteAppsPageBrowsePage = new Page(siteAppsPageFolder);
siteAppsPageBrowsePage.Name = "Browse";
siteAppsPageBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page Browse App</h1></body></html>"));
siteAppsPageBrowsePage.Save();
}
var siteAppsPageEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Edit");
if (siteAppsPageEditPage == null)
{
siteAppsPageEditPage = new Page(siteAppsPageFolder);
siteAppsPageEditPage.Name = "Edit";
siteAppsPageEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page EditPage</h1></body></html>"));
siteAppsPageEditPage.Save();
}
var siteAppsGenericContentFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/GenericContent");
if (siteAppsGenericContentFolder == null)
{
siteAppsGenericContentFolder = new SystemFolder(siteAppsFolder);
siteAppsGenericContentFolder.Name = "GenericContent";
siteAppsGenericContentFolder.Save();
}
var siteAppsGenericContentBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Browse");
if (siteAppsGenericContentBrowsePage == null)
{
siteAppsGenericContentBrowsePage = new Page(siteAppsGenericContentFolder);
siteAppsGenericContentBrowsePage.Name = "Browse";
siteAppsGenericContentBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent Browse App</h1></body></html>"));
siteAppsGenericContentBrowsePage.Save();
}
var siteAppsGenericContentEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
if (siteAppsGenericContentEditPage == null)
{
siteAppsGenericContentEditPage = new Page(siteAppsGenericContentFolder);
siteAppsGenericContentEditPage.Name = "Edit";
siteAppsGenericContentEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent EditPage</h1></body></html>"));
siteAppsGenericContentEditPage.Save();
}
//---- SelfDispatcher node
var selfDispatcherContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/SelfDispatcherContent1");
if (selfDispatcherContent == null)
{
selfDispatcherContent = new GenericContent(homePage, "WebContent");
selfDispatcherContent.Name = "SelfDispatcherContent1";
selfDispatcherContent.BrowseApplication = Node.LoadNode("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
selfDispatcherContent.Save();
}
}
示例2: BinaryData_EmptyWrite
public void BinaryData_EmptyWrite()
{
// Save binary
File file = new File(this.TestRoot);
BinaryData target = new BinaryData();
file.Binary = target;
file.Save();
int id = file.Id;
// Load binary back
file = (File)Node.LoadNode(id);
Assert.IsTrue(file.GetBinary("Binary").IsEmpty);
//Assert.AreNotEqual(0, file.Binary.Id);
//Assert.AreEqual(string.Empty, file.Binary.ContentType);
//Assert.AreEqual(string.Empty, file.Binary.FileName.FullFileName);
//Assert.AreEqual((long)-1, file.Binary.Size);
//Assert.AreEqual(null, file.Binary.GetStream());
}