本文整理汇总了C#中System.Web.HttpFileCollectionBase类的典型用法代码示例。如果您正苦于以下问题:C# HttpFileCollectionBase类的具体用法?C# HttpFileCollectionBase怎么用?C# HttpFileCollectionBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpFileCollectionBase类属于System.Web命名空间,在下文中一共展示了HttpFileCollectionBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ledgarl,项目名称:Samples,代码行数:25,代码来源:FileCollectionModelBinder.cs
示例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;
}
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:35,代码来源:EntityService.cs
示例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;
}
开发者ID:rogerxing90,项目名称:AHome,代码行数:40,代码来源:FileUpload.cs
示例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;
}
开发者ID:dminik,项目名称:voda_code,代码行数:31,代码来源:OFormService.cs
示例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;
}
开发者ID:panjiyang,项目名称:Bode,代码行数:36,代码来源:UploadHelper.cs
示例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);
}
开发者ID:pampas3,项目名称:KoobooCMS,代码行数:35,代码来源:ModelExtensions.cs
示例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;
}
开发者ID:anupvarghese,项目名称:Ilaro.Admin,代码行数:29,代码来源:EntityService.cs
示例8: CmisHttpFileCollectionWrapper
// Methods
public CmisHttpFileCollectionWrapper(HttpFileCollectionBase files)
{
foreach (var key in files.AllKeys)
{
this.AddFile(key, files[key]);
}
}
开发者ID:Epitomy,项目名称:CMS,代码行数:8,代码来源:CmisHttpPostedFileWrapper.cs
示例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();
}
开发者ID:reslea,项目名称:EduKeeper,代码行数:34,代码来源:FileService.cs
示例10: HttpFileCollectionBaseWrapper
// Methods
public HttpFileCollectionBaseWrapper(HttpFileCollectionBase httpFileCollection)
{
if (httpFileCollection == null)
{
throw new ArgumentNullException("httpFileCollection");
}
this._collection = httpFileCollection;
}
开发者ID:Epitomy,项目名称:CMS,代码行数:9,代码来源:HttpFileCollectionBaseWrapper.cs
示例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);
}
开发者ID:Godoy,项目名称:CMS,代码行数:8,代码来源:ContactSitePlugin.cs
示例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);
}
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:8,代码来源:EntityExtensions.cs
示例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;
}
开发者ID:frapid,项目名称:frapid,代码行数:9,代码来源:Uploader.cs
示例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 "";
}
开发者ID:ByBox,项目名称:roadkill,代码行数:10,代码来源:FileServiceMock.cs
示例15: UploadedFileCollection
internal UploadedFileCollection(HttpFileCollectionBase collection)
{
if (collection == null)
{
throw new ArgumentNullException("collection");
}
m_collection = new List<IUploadedFile>();
PopulateFiles(collection);
}
开发者ID:dstarosta,项目名称:GitProjects,代码行数:11,代码来源:UploadedFileCollection.cs
示例16: CreateAttachments
public void CreateAttachments(HttpFileCollectionBase files, int postID)
{
foreach (string filename in files)
{
HttpPostedFileBase f = files[filename];
if (f.ContentLength > 0)
{
CreateAttachment(f, postID);
}
}
}
开发者ID:dineshkummarc,项目名称:mesoBoard,代码行数:11,代码来源:FileServices.cs
示例17: isImageFound
public static Boolean isImageFound(HttpFileCollectionBase files)
{
foreach (string file in files)
{
HttpPostedFileBase hpf = (HttpPostedFileBase)files[file];
if (hpf.ContentLength == 0)
return false;
}
return true;
}
开发者ID:DCruz22,项目名称:MusicHub,代码行数:12,代码来源:FilesHelper.cs
示例18: CreateMarketingCampaign
public static MarketingCampaign CreateMarketingCampaign(string companyName, string website, string city, string country,
string username, string email, string phone, HttpFileCollectionBase postedFiles, string description,
HttpPostedFileBase logoFile, string referringURL, Action<EntityContext, Company> createPortfolios)
{
var context = new Entities();
if (Account.Exists(username))
throw new Exception("The username already exists.");
var account = new Account();
account.Username = username;
account.Password = AgileFx.Security.CryptoUtil.HashPassword(Guid.NewGuid().ToString());
account.Status = ACCOUNT_STATUS.ACTIVE;
account.LastLoginDate = DateTime.Now;
account.DateAdded = DateTime.Now;
account.Type = ACCOUNT_TYPE.COMPANY;
account.Email = email;
var company = new Company();
company.Account = account;
company.Name = companyName;
company.Website = website;
company.City = city;
company.Country = country;
company.Phone = phone;
if (logoFile.ContentLength > 0)
company.SaveLogo(logoFile);
company.Description = description;
foreach (var tag in context.Tag.Where(t => t.Name == "Web Design" || t.Name == ""))
company.Tags.Add(tag);
createPortfolios(context, company);
context.AddObject(company);
context.SaveChanges();
var marketingCamp = new MarketingCampaign();
marketingCamp.Account = account.Id;
marketingCamp.DateCreated = DateTime.UtcNow;
marketingCamp.DateModified = DateTime.UtcNow;
marketingCamp.ReferringURL = referringURL;
marketingCamp.Status = MARKETING_CAMPAIGN_STATUS.NEW;
marketingCamp.Token = Guid.NewGuid();
context.AddObject(marketingCamp);
context.SaveChanges();
return marketingCamp;
}
开发者ID:jeswin,项目名称:CanYouCode,代码行数:52,代码来源:MarketingUtil.cs
示例19: UploadImages
/// <summary>
/// Uploads a colletion of files to the image server
/// </summary>
/// <param name="files">the files to upload</param>
/// <param name="imagePath">The path to save the image to</param>
/// <returns>list of result objects with filename and success / fail messages</returns>
public IList<ImageUploadResult> UploadImages(HttpFileCollectionBase files, string imagePath)
{
// Upload hte image to the storage
IList<ImageUploadResult> results = this._imageStorage.UploadImages(files, this._website.Domain, imagePath);
foreach (ImageUploadResult result in results)
{
Image image = this.SaveImage(new Image(result, this._website.Id));
result.ImageId = image.Id;
}
return results;
}
开发者ID:Brontsy,项目名称:Castlerock,代码行数:19,代码来源:ImageService.cs
示例20: IsAllowedLengthForFiles
/// <summary>
/// 判断上传文件组里的文件大小是否超过最大值
/// </summary>
/// <param name="files">上传的文件组</param>
/// <returns>超过最大值返回false,否则返回true.</returns>
public static bool IsAllowedLengthForFiles(HttpFileCollectionBase files)
{
for (int i = 0; i < files.Count; i++)
{
HttpPostedFileBase file = files[i];
if (!IsAllowedLengthForFile(file))
{
return false;
}
}
return true;
}
开发者ID:dalinhuang,项目名称:newcqgj,代码行数:19,代码来源:FileUpload.cs
注:本文中的System.Web.HttpFileCollectionBase类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论