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)); } } }
/// <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; }
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; }
/// <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; }