本文整理汇总了C#中File.CheckOut方法的典型用法代码示例。如果您正苦于以下问题:C# File.CheckOut方法的具体用法?C# File.CheckOut怎么用?C# File.CheckOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File.CheckOut方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithSafeFileOperation
public static void WithSafeFileOperation(List list, File file,
Func<File, File> action, Action<File> onCreated,
bool doesFileHasListItem)
{
var context = list.Context;
context.Load(list, l => l.EnableMinorVersions);
context.Load(list, l => l.EnableModeration);
context.Load(list, l => l.BaseType);
context.ExecuteQueryWithTrace();
if (file != null)
{
context.Load(file, f => f.Exists);
context.ExecuteQueryWithTrace();
if (file.Exists)
{
context.Load(file);
context.Load(file, f => f.CheckOutType);
context.Load(file, f => f.CheckedOutByUser);
context.Load(file, f => f.Level);
context.ExecuteQueryWithTrace();
}
}
var shouldRefreshLoad = false;
// are we inside ocument libary, so that check in stuff is needed?
var isDocumentLibrary = list != null && list.BaseType == BaseType.DocumentLibrary;
if (isDocumentLibrary && doesFileHasListItem)
{
if (list != null && file != null && (file.Exists && file.CheckOutType != CheckOutType.None))
{
file.UndoCheckOut();
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
if (list != null && file != null && (list.EnableMinorVersions) &&
(file.Exists && file.Level == FileLevel.Published))
{
file.UnPublish("Provision");
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
if (list != null && file != null && (file.Exists && file.CheckOutType == CheckOutType.None))
{
file.CheckOut();
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
}
var spFile = action(file);
context.ExecuteQueryWithTrace();
context.Load(spFile);
context.Load(spFile, f => f.Exists);
context.ExecuteQueryWithTrace();
if (spFile.Exists)
{
// super hack with doesFileHasListItem
// once filed under Forms folder
// CanDeploy_WebpartTo_ListForm_InLibrary / CanDeploy_WebpartTo_ListForm_InLibrary
if (isDocumentLibrary && doesFileHasListItem)
{
if (spFile.ListItemAllFields != null)
{
// weird issues while deployin in a row for wiki
if (list.BaseTemplate != 119)
{
spFile.ListItemAllFields.Update();
}
}
}
context.ExecuteQueryWithTrace();
if (onCreated != null)
onCreated(spFile);
context.Load(spFile);
context.Load(spFile, f => f.CheckOutType);
context.Load(spFile, f => f.Level);
context.ExecuteQueryWithTrace();
}
//.........这里部分代码省略.........
示例2: WithSafeFileOperation
public static void WithSafeFileOperation(List list, File file, Func<File, File> action, Action<File> onCreated)
{
var context = list.Context;
context.Load(list, l => l.EnableMinorVersions);
context.Load(list, l => l.EnableModeration);
context.Load(list, l => l.BaseType);
context.ExecuteQueryWithTrace();
if (file != null)
{
context.Load(file, f => f.Exists);
context.ExecuteQueryWithTrace();
if (file.Exists)
{
context.Load(file, f => f.CheckOutType);
context.Load(file, f => f.CheckedOutByUser);
context.Load(file, f => f.Level);
context.ExecuteQueryWithTrace();
}
}
var shouldRefreshLoad = false;
// are we inside ocument libary, so that check in stuff is needed?
var isDocumentLibrary = list != null && list.BaseType == BaseType.DocumentLibrary;
if (isDocumentLibrary)
{
if (list != null && file != null && (file.Exists && file.CheckOutType != CheckOutType.None))
{
file.UndoCheckOut();
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
if (list != null && file != null && (list.EnableMinorVersions) &&
(file.Exists && file.Level == FileLevel.Published))
{
file.UnPublish("Provision");
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
if (list != null && file != null && (file.Exists && file.CheckOutType == CheckOutType.None))
{
file.CheckOut();
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
}
var spFile = action(file);
context.ExecuteQueryWithTrace();
context.Load(spFile, f => f.Exists);
context.ExecuteQueryWithTrace();
if (spFile.Exists)
{
if (isDocumentLibrary)
{
spFile.ListItemAllFields.Update();
}
context.ExecuteQueryWithTrace();
if (onCreated != null)
onCreated(spFile);
context.Load(spFile, f => f.CheckOutType);
context.Load(spFile, f => f.Level);
context.ExecuteQueryWithTrace();
}
if (isDocumentLibrary)
{
if (list != null && spFile != null && (spFile.Exists && spFile.CheckOutType != CheckOutType.None))
spFile.CheckIn("Provision", CheckinType.MajorCheckIn);
if (list != null && spFile != null && (list.EnableMinorVersions))
spFile.Publish("Provision");
if (list != null && spFile != null && (list.EnableModeration))
spFile.Approve("Provision");
}
context.ExecuteQueryWithTrace();
}
示例3: Bug1308Test
public void Bug1308Test()
{
const string fileName = "bug1308.xml";
const string fileBinary = @"<?xml version='1.0' encoding='utf-8'?> <ContentType><Fields /></ContentType>";
var test = new File(TestRoot);
test.Name = fileName;
test.Binary.SetStream(Tools.GetStreamFromString(fileBinary));
test.Binary.FileName = fileName;
test.Save();
//1. checkout
test.CheckOut();
//2. checkin
var exceptionOccured = false;
try
{
test.UndoCheckOut();
}
catch (NullReferenceException)
{
exceptionOccured = true;
}
//assert
var errorMessage = String.Concat("Version history should be V1.0.A instead of: ", GetVersionHistoryString(NodeHead.Get(test.Id)));
Assert.IsFalse(exceptionOccured, String.Concat("An exception occured during execution.", errorMessage));
AssertVersionHistory(test, "V1.0.A", errorMessage);
}
示例4: WithSafeFileOperation
public static void WithSafeFileOperation(List list, File file,
Func<File, File> action, Action<File> onCreated,
bool doesFileHasListItem)
{
var context = list.Context;
context.Load(list, l => l.EnableMinorVersions);
context.Load(list, l => l.EnableModeration);
context.Load(list, l => l.BaseType);
context.ExecuteQueryWithTrace();
if (file != null)
{
context.Load(file, f => f.Exists);
context.ExecuteQueryWithTrace();
if (file.Exists)
{
context.Load(file);
context.Load(file, f => f.CheckOutType);
context.Load(file, f => f.CheckedOutByUser);
context.Load(file, f => f.Level);
context.ExecuteQueryWithTrace();
}
}
// are we inside ocument libary, so that check in stuff is needed?
var isDocumentLibrary = list != null && list.BaseType == BaseType.DocumentLibrary;
if (isDocumentLibrary && doesFileHasListItem)
{
if (list != null && file != null && (file.Exists && file.CheckOutType != CheckOutType.None))
{
file.UndoCheckOut();
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
if (list != null && file != null && (list.EnableMinorVersions) &&
(file.Exists && file.Level == FileLevel.Published))
{
file.UnPublish("Provision");
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
if (list != null && file != null && (file.Exists && file.CheckOutType == CheckOutType.None))
{
file.CheckOut();
file.RefreshLoad();
context.ExecuteQueryWithTrace();
}
}
var spFile = action(file);
context.ExecuteQueryWithTrace();
context.Load(spFile);
context.Load(spFile, f => f.Exists);
context.ExecuteQueryWithTrace();
if (spFile.Exists)
{
// super hack with doesFileHasListItem
// once filed under Forms folder
// CanDeploy_WebpartTo_ListForm_InLibrary / CanDeploy_WebpartTo_ListForm_InLibrary
if (isDocumentLibrary && doesFileHasListItem)
{
if (spFile.ListItemAllFields != null)
{
// weird issues while deployin in a row for wiki
if (list.BaseTemplate != 119)
{
spFile.ListItemAllFields.Update();
}
}
}
context.ExecuteQueryWithTrace();
if (onCreated != null)
onCreated(spFile);
context.Load(spFile);
context.Load(spFile, f => f.CheckOutType);
context.Load(spFile, f => f.Level);
context.ExecuteQueryWithTrace();
}
// super hack with doesFileHasListItem
//.........这里部分代码省略.........
示例5: WithSafeFileOperation
//private File GetFile()
//{
//}
private void WithSafeFileOperation(List list, File file, Func<File, File> action)
{
var context = file.Context;
context.Load(file, f => f.Exists);
context.ExecuteQuery();
if (file.Exists)
{
context.Load(file, f => f.CheckOutType);
context.Load(file, f => f.Level);
context.ExecuteQuery();
}
// big todo with correct update and punblishing
// get prev SPMeta2 impl for publishing pages
if (list != null && (file.Exists && file.CheckOutType != CheckOutType.None))
file.UndoCheckOut();
if (list != null && (list.EnableMinorVersions || list.EnableVersioning) && (file.Exists && file.Level == FileLevel.Published))
file.UnPublish("Provision");
if (list != null && (file.Exists && file.CheckOutType == CheckOutType.None))
file.CheckOut();
context.ExecuteQuery();
var spFile = action(file);
context.ExecuteQuery();
context.Load(spFile, f => f.Exists);
context.ExecuteQuery();
if (spFile.Exists)
{
context.Load(spFile, f => f.CheckOutType);
context.Load(spFile, f => f.Level);
context.ExecuteQuery();
}
if (list != null && (spFile.Exists && spFile.CheckOutType != CheckOutType.None))
spFile.CheckIn("", CheckinType.MajorCheckIn);
if (list != null && (list.EnableMinorVersions || list.EnableVersioning))
spFile.Publish("Provision");
if (list != null && (list.EnableModeration))
spFile.Approve("Provision");
context.ExecuteQuery();
}