本文整理汇总了C#中System.Web.HttpFileCollectionBase类的典型用法代码示例。如果您正苦于以下问题:C# HttpFileCollectionBase类的具体用法?C# HttpFileCollectionBase怎么用?C# HttpFileCollectionBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpFileCollectionBase类属于System.Web命名空间,在下文中一共展示了HttpFileCollectionBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFiles
private static List<HttpPostedFileBase> GetFiles(HttpFileCollectionBase fileCollection, string key) {
// first, check for any files matching the key exactly
List<HttpPostedFileBase> files = fileCollection.AllKeys
.Select((thisKey, index) => (String.Equals(thisKey, key, StringComparison.OrdinalIgnoreCase)) ? index : -1)
.Where(index => index >= 0)
.Select(index => fileCollection[index])
.ToList();
if (files.Count == 0) {
// then check for files matching key[0], key[1], etc.
for (int i = 0; ; i++) {
string subKey = String.Format(CultureInfo.InvariantCulture, "{0}[{1}]", key, i);
HttpPostedFileBase thisFile = fileCollection[subKey];
if (thisFile == null) {
break;
}
files.Add(thisFile);
}
}
// if an <input type="file" /> element was rendered on the page but the user did not select a file before posting
// the form, null out that entry in the list.
List<HttpPostedFileBase> filteredFiles = files.ConvertAll((Converter<HttpPostedFileBase, HttpPostedFileBase>)ChooseFileContentOrNull);
return filteredFiles;
}
示例2: Create
public string Create(
Entity entity,
FormCollection collection,
HttpFileCollectionBase files)
{
var entityRecord = entity.CreateRecord(collection, files, x => x.OnCreateDefaultValue);
if (_validator.Validate(entityRecord) == false)
{
_notificator.Error(IlaroAdminResources.RecordNotValid);
return null;
}
var existingRecord = _source.GetRecord(
entity,
entityRecord.Keys.Select(value => value.AsObject).ToArray());
if (existingRecord != null)
{
_notificator.Error(IlaroAdminResources.EntityAlreadyExist);
return null;
}
var propertiesWithUploadedFiles = _filesHandler.Upload(
entityRecord,
x => x.OnCreateDefaultValue);
var id = _creator.Create(
entityRecord,
() => _changeDescriber.CreateChanges(entityRecord));
if (id.IsNullOrWhiteSpace() == false)
_filesHandler.ProcessUploaded(propertiesWithUploadedFiles);
else
_filesHandler.DeleteUploaded(propertiesWithUploadedFiles);
return id;
}
示例3: FileUploadSingle
/// <summary>
/// 单个文件上传(只获取第一个文件,返回的文件名是文件的md5值),返回为json数据格式,成功返回{status:"success",website:"a.jpg"},失败,返回{status:"error",website:"error"}
/// </summary>
/// <param name="context">上下文</param>
/// <param name="FilePath">文件路径</param>
/// <param name="outFileName">返回文件的md5</param>
/// <returns>返回json状态信息</returns>
public static bool FileUploadSingle(HttpFileCollectionBase files, string FilePath, out string outFileName)
{
//string json = "";
//找到目标文件对象
HttpFileCollectionBase hfc = files;
HttpPostedFileBase hpf = hfc[0];
if (hpf.ContentLength > 0)
{
//根据文件的md5的hash值做文件名,防止文件的重复和图片的浪费
string FileName = CreateFileForFileNameByMd5(hpf.FileName); //CreateDateTimeForFileName(hpf.FileName);//自动生成文件名
string file = System.IO.Path.Combine(FilePath,
FileName);
if (!Directory.Exists(Path.GetDirectoryName(file)))
{
Directory.CreateDirectory(file);
}
hpf.SaveAs(file);
//此处改为返回filePath,回显图片更新页面Image的src
//json = "{status:\"success\", fileName:\"" + FileName+ "\" ,filePath:\"" + FilePath + "\"}";
outFileName = FileName;
return true;
}
else
{
//json = "{status:\"error\", fileName:\"error\", filePath:\"error\"}";
outFileName = FilePath;
return false;
}
//return json;
}
示例4: SaveFormToDB
private OFormResultRecord SaveFormToDB(OFormPart form, Dictionary<string, string> postData, HttpFileCollectionBase files, string ipSubmiter)
{
var xdoc = ConvertToXDocument(postData);
var resultRecord = new OFormResultRecord
{
Xml = xdoc.ToString(),
CreatedDate = DateTime.UtcNow,
Ip = ipSubmiter,
CreatedBy = postData[OFormGlobals.CreatedByKey]
};
if (form.CanUploadFiles && files.Count > 0)
{
foreach (string key in files.Keys)
{
if (files[key].ContentLength == 0) { continue; }
CheckFileSize(form, files[key]);
CheckFileType(form, files[key]);
var formFile = SaveFile(key, files[key]);
resultRecord.AddFile(formFile);
}
}
this._resultRepo.Create(resultRecord);
form.Record.AddFormResult(resultRecord);
_contentManager.Flush();
return resultRecord;
}
示例5: MvcUpload
/// <summary>
/// 文件上传
/// </summary>
/// <param name="hfc">客户端上传文件流</param>
/// <param name="afterPath">类似:aaaa/bbb/子文件夹</param>
/// <returns></returns>
public static List<string> MvcUpload(HttpFileCollectionBase hfc, string afterPath = "")
{
string path = UploadRoot + afterPath;
List<string> theList = new List<string>();
string filePath = HttpContext.Current.Server.MapPath(path);
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
foreach (string item in hfc)
{
if (hfc[item] == null || hfc[item].ContentLength == 0) continue;
try
{
string fileExtension = Path.GetExtension(hfc[item].FileName);
var fileName = Guid.NewGuid().ToString() + fileExtension;
hfc[item].SaveAs(filePath + fileName);
string strSqlPath = (path + fileName).Replace("~/", ServerHost);
theList.Add(strSqlPath);
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex);
}
}
return theList;
}
示例6: SendMailToSiteManager
public static void SendMailToSiteManager(this Site site, string from, string subject, string body, bool isBodyHtml, HttpFileCollectionBase files = null)
{
var smtp = site.Smtp;
if (smtp == null)
{
throw new ArgumentNullException("smtp");
}
MailMessage message = new MailMessage() { From = new MailAddress(from) };
foreach (var item in smtp.To)
{
if (!string.IsNullOrEmpty(item))
{
message.To.Add(item);
}
}
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = isBodyHtml;
if (files != null && files.Count > 0)
{
foreach (string key in files.AllKeys)
{
HttpPostedFileBase file = files[key] as HttpPostedFileBase;
message.Attachments.Add(new Attachment(file.InputStream, file.FileName, IO.IOUtility.MimeType(file.FileName)));
}
}
SmtpClient smtpClient = smtp.ToSmtpClient();
smtpClient.Send(message);
}
示例7: Create
public string Create(
Entity entity,
FormCollection collection,
HttpFileCollectionBase files)
{
entity.Fill(collection, files);
if (_validator.Validate(entity) == false)
{
_notificator.Error("Not valid");
return null;
}
var existingRecord = _source.GetRecord(entity, entity.Key.Select(x => x.Value.AsObject));
if (existingRecord != null)
{
_notificator.Error(IlaroAdminResources.EntityAlreadyExist);
return null;
}
var propertiesWithUploadedFiles = _filesHandler.Upload(entity);
var id = _creator.Create(entity, () => _changeDescriber.CreateChanges(entity));
if (id.IsNullOrWhiteSpace() == false)
_filesHandler.ProcessUploaded(propertiesWithUploadedFiles);
else
_filesHandler.DeleteUploaded(propertiesWithUploadedFiles);
return id;
}
示例8: CmisHttpFileCollectionWrapper
// Methods
public CmisHttpFileCollectionWrapper(HttpFileCollectionBase files)
{
foreach (var key in files.AllKeys)
{
this.AddFile(key, files[key]);
}
}
示例9: Attach
public void Attach(int postId, int courseId, HttpFileCollectionBase files)
{
CheckAccessToPost(postId);
if (files.Count == 0)
return;
for (var i = 0; i < files.Count; i++)
{
if (files[i] == null) continue;
if (files[i].ContentLength > 29 * 1024 * 1024) continue; // 100 MB
var identifier = Guid.NewGuid();
var guidName = identifier.ToString();
var courseDirectory = GetCourseDirectory(courseId);
var extention = Path.GetExtension(files[i].FileName);
var path = Path.Combine(courseDirectory, guidName + extention);
files[i].SaveAs(path);
Repository.Add(new Entities.File()
{
Name = files[i].FileName.Substring(0, files[i].FileName.Length < 100 ? files[i].FileName.Length : 100),
Path = path,
PostId = postId,
Identifier = identifier
});
}
Repository.Save();
}
示例10: HttpFileCollectionBaseWrapper
// Methods
public HttpFileCollectionBaseWrapper(HttpFileCollectionBase httpFileCollection)
{
if (httpFileCollection == null)
{
throw new ArgumentNullException("httpFileCollection");
}
this._collection = httpFileCollection;
}
示例11: SendMail
protected virtual void SendMail(ControllerContext controllerContext, Site site, ContactSiteModel ContactSiteModel, HttpFileCollectionBase files) {
var from = ContactSiteModel.From;
var subject = ContactSiteModel.Subject;
var body = string.Format(ContactSiteModel.EmailBody ,ContactSiteModel.From, ContactSiteModel.Subject, ContactSiteModel.Body);
site.SendMailToSiteManager(from, subject, body, true , files);
}
示例12: CreateRecord
public static EntityRecord CreateRecord(
this Entity entity,
IValueProvider valueProvider,
HttpFileCollectionBase files,
Func<Property, object> defaultValueResolver = null)
{
return EntityRecordCreator.CreateRecord(entity, valueProvider, files, defaultValueResolver);
}
示例13: Uploader
public Uploader(ILogger logger, AreaRegistration area, HttpFileCollectionBase files, string tenant,
string[] allowedExtensions)
{
this.Logger = logger;
this.Area = area;
this.Files = files;
this.Tenant = tenant;
this.AllowedExtensions = allowedExtensions;
}
示例14: Upload
public string Upload(string destinationPath, HttpFileCollectionBase files)
{
if (CustomException != null)
throw CustomException;
if (files.Count > 0)
return files[files.Count - 1].FileName;
else
return "";
}
示例15: UploadedFileCollection
internal UploadedFileCollection(HttpFileCollectionBase collection)
{
if (collection == null)
{
throw new ArgumentNullException("collection");
}
m_collection = new List<IUploadedFile>();
PopulateFiles(collection);
}