本文整理汇总了C#中System.Web.HttpFileCollectionBase.Get方法的典型用法代码示例。如果您正苦于以下问题:C# HttpFileCollectionBase.Get方法的具体用法?C# HttpFileCollectionBase.Get怎么用?C# HttpFileCollectionBase.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpFileCollectionBase
的用法示例。
在下文中一共展示了HttpFileCollectionBase.Get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateFiles
private void PopulateFiles(HttpFileCollectionBase collection)
{
foreach (string fileName in collection.AllKeys)
{
var postedFile = collection.Get(fileName);
if (postedFile != null)
{
m_collection.Add(new UploadedFile(postedFile));
}
}
}
示例2: SaveMultipleFiles
/// <summary>
/// Not in use for mobile end i.e. this is not a service for android or ios
/// </summary>
/// <param name="collection"></param>
/// <param name="fileName"></param>
/// <returns></returns>
List<string> SaveMultipleFiles(HttpFileCollectionBase collection, string fileName)
{
List<string> UniqueFileNames = new List<string>();
string ext = "";
string path = HttpContext.Current.Request.PhysicalApplicationPath + "tutorDocs\\";
if (collection.Count > 0)
{
#region LoopFor multipleFiles upload and save and get their names
for (int i = 0; i < collection.Count; i++)
{
HttpPostedFileBase postedFile = collection.Get(i);
ext = Path.GetExtension(postedFile.FileName).ToLower();
if (string.IsNullOrEmpty(fileName))
{
UniqueFileNames.Add(Guid.NewGuid().ToString("n") + ext);
}
else
{
if (File.Exists(@path + fileName))
{
File.Delete(@path + fileName);
}
UniqueFileNames[i] = fileName;
}
postedFile.SaveAs(path + UniqueFileNames[i]);
}
#endregion
}
return UniqueFileNames;
}
示例3: SaveImage
string SaveImage(HttpFileCollectionBase collection, string imageName)
{
string UniqueFileName = imageName;
string path = HttpContext.Current.Request.PhysicalApplicationPath + "WebImages\\";
if (collection.Count > 0)
{
if (string.IsNullOrEmpty(imageName))
{
UniqueFileName = Guid.NewGuid().ToString("n") + ".jpg";
}
else
{
if (File.Exists(@path + imageName))
{
File.Delete(@path + imageName);
}
UniqueFileName = imageName;
}
HttpPostedFileBase imgFile = collection.Get(0);
if (imgFile.ContentType == "image/jpeg" || imgFile.ContentType == "image/png" || imgFile.ContentType == "image/*")
{
Stream requestStream = imgFile.InputStream;
Image img = System.Drawing.Image.FromStream(requestStream);
img.Save(path + UniqueFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
requestStream.Close();
}
else
{
if (Constants.isProduction.ToLower() == "true")
{
Stream requestStream = imgFile.InputStream;
Image img = System.Drawing.Image.FromStream(requestStream);
img.Save(path + UniqueFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
requestStream.Close();
}
}
}
return UniqueFileName;
}
示例4: SaveFile
/// <summary>
///[tutor] Accepting a student from the tutor
/// </summary>
/// <developer>Rishabh </developer>
/// <param name="objReq"></param>
/// <returns></returns>
//[HttpPost]
//public Response<string> AcceptStudent(StudentTeacherMap objReq)
//{
// Response<string> response = new Response<string>();
// List<string> objResp = new List<string>();
// try
// {
// WebMethods obj = new WebMethods();
// if (CheckRequestIsvalidornot(this.Request))
// {
// if (ModelState.IsValid)
// {
// if (obj.AcceptStudent(objReq))
// response.Create(true, "Student is Accepted", Messages.AppVersion, objResp);
// else
// response.Create(false, "The student request you are accepting is already accepted by any other tutor.Please refresh the screen for new request.", Messages.AppVersion, objResp);
// }
// else
// response.Create(false, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage, Messages.AppVersion, objResp);
// }
// }
// catch (Exception ex)
// {
// object session = new JavaScriptSerializer().Serialize(objReq);
// LogManager.Error("Error occured while Processing Webservice request :{0}", ex, session, ex.Message);
// response.Create(false, Messages.FormatMessage(Messages.ErrorOccure), Messages.AppVersion, objResp);
// }
// return response;
//}
public string SaveFile(HttpFileCollectionBase collection, string fileName)
{
string UniqueFileName = "";
string ext = "";
string path = HttpContext.Current.Request.PhysicalApplicationPath + "tutorDocs\\";
if (collection.Count > 0)
{
HttpPostedFileBase postedFile = collection.Get(0);
ext = Path.GetExtension(postedFile.FileName).ToLower();
if (string.IsNullOrEmpty(fileName))
{
UniqueFileName = Guid.NewGuid().ToString("n") + ext;
}
else
{
if (File.Exists(@path + fileName))
{
File.Delete(@path + fileName);
}
UniqueFileName = fileName;
}
postedFile.SaveAs(path + UniqueFileName);
}
return UniqueFileName;
}