本文整理汇总了C#中System.Web.HttpFileCollectionBase.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# HttpFileCollectionBase.GetKey方法的具体用法?C# HttpFileCollectionBase.GetKey怎么用?C# HttpFileCollectionBase.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpFileCollectionBase
的用法示例。
在下文中一共展示了HttpFileCollectionBase.GetKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AdminSaveProblemData
/// <summary>
/// 保存题目数据文件到磁盘
/// </summary>
/// <param name="problemID">题目ID</param>
/// <param name="forms">Request.Forms</param>
/// <param name="httpFiles">Request.Files</param>
/// <returns>是否保存成功</returns>
public static IMethodResult AdminSaveProblemData(Int32 problemID, NameValueCollection forms, HttpFileCollectionBase httpFiles)
{
if (!AdminManager.HasPermission(PermissionType.ProblemManage))
{
throw new NoPermissionException();
}
if (problemID < ConfigurationManager.ProblemSetStartID)
{
return MethodResult.InvalidRequest(RequestType.Problem);
}
SortedDictionary<String, String> dictData = new SortedDictionary<String, String>();
if (httpFiles != null)
{
for (Int32 i = 0; i < httpFiles.Count; i++)
{
HttpPostedFileBase file = httpFiles[i];
if (String.IsNullOrEmpty(file.FileName))
{
return MethodResult.FailedAndLog("Filename can not be NULL!");
}
FileInfo fi = new FileInfo(file.FileName);
if (httpFiles.GetKey(i).IndexOf("in", StringComparison.OrdinalIgnoreCase) == 0 && !".in".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase))
{
return MethodResult.FailedAndLog("Filename is INVALID!");
}
if (httpFiles.GetKey(i).IndexOf("out", StringComparison.OrdinalIgnoreCase) == 0 && !".out".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase) && !".ans".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase))
{
return MethodResult.FailedAndLog("Filename is INVALID!");
}
if (file.ContentLength <= 0)
{
return MethodResult.FailedAndLog("You can not upload empty file!");
}
StreamReader sr = new StreamReader(file.InputStream);
dictData.Add(httpFiles.GetKey(i), sr.ReadToEnd());
}
}
if (forms != null)
{
for (Int32 i = 0; i < forms.Count; i++)
{
if (forms.GetKey(i).IndexOf("in", StringComparison.OrdinalIgnoreCase) == 0 || forms.GetKey(i).IndexOf("out", StringComparison.OrdinalIgnoreCase) == 0)
{
dictData.Add(forms.GetKey(i), forms[i]);
}
}
}
if (dictData.Count == 0)
{
return MethodResult.FailedAndLog("No data was added!");
}
if (dictData.Count % 2 != 0)
{
return MethodResult.FailedAndLog("The count of uploaded data is INVALID!");
}
ProblemDataWriter writer = new ProblemDataWriter();
foreach (KeyValuePair<String, String> pair in dictData)
{
if (pair.Key.IndexOf("in", StringComparison.OrdinalIgnoreCase) == 0)
{
String input = pair.Value;
String output = String.Empty;
if (!dictData.TryGetValue(pair.Key.ToLower().Replace("in", "out"), out output))
{
return MethodResult.FailedAndLog("The count of uploaded data is INVALID!");
}
writer.WriteData(input, output);
}
}
String fileNewName = problemID.ToString() + ".zip";
String savePath = Path.Combine(ConfigurationManager.ProblemDataPath, fileNewName);
Byte[] data = writer.WriteTo();
File.WriteAllBytes(savePath, data);
ProblemDataCache.RemoveProblemDataVersionCache(problemID);
return MethodResult.SuccessAndLog("Admin create problem data, id = {0}", problemID.ToString());
//.........这里部分代码省略.........