protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } if (e.State != AjaxControlToolkit.AjaxFileUploadState.Success) { return; } string szKey = FileObjectSessionKey(e.FileId); PendingIDs.Add(szKey); Session[szKey] = new MFBPendingImage(new MFBPostedFile(e.FileName, e.ContentType, e.FileSize, e.GetContents(), e.FileId), szKey); e.DeleteTemporaryData(); RefreshPreviewList(); if (Mode == UploadMode.Legacy) { Mode = UploadMode.Ajax; } if (UploadComplete != null) { UploadComplete(this, e); } }
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { byte[] image = e.GetContents(); MembershipUser currentUser = Membership.GetUser(); if (currentUser != null) { currentUserId = (Guid)currentUser.ProviderUserKey; string connectionString = ConfigurationManager.ConnectionStrings["SecurityConnectionString"].ConnectionString; string updateSql = "UPDATE UserProfiles SET BackgroundPicture = @BackgroundPicture WHERE UserId = @UserId"; try { using (SqlConnection myConnection = new SqlConnection(connectionString)) { myConnection.Open(); SqlCommand myCommand = new SqlCommand(updateSql, myConnection); myCommand.Parameters.AddWithValue("@UserId", currentUserId); myCommand.Parameters.AddWithValue("@BackgroundPicture", image); myCommand.ExecuteNonQuery(); myConnection.Close(); } } catch { } } this.DataBind(); e.DeleteTemporaryData(); }
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { string filename = Path.GetFileName(e.FileName); string ruta = Server.MapPath("~/TMP"); // Si el directorio no existe, crearlo if (!Directory.Exists(ruta)) { Directory.CreateDirectory(ruta); } string archivo = String.Format("{0}\\{1}", ruta, filename); // Verificar que el archivo no exista if (File.Exists(archivo)) { lblError.Text = (String.Format("Ya existe Documento con nombre\"{0}\".", filename)); } else { AjaxFileUpload1.SaveAs(ruta + "\\" + filename); } Session["archivo"] = ruta + "\\" + filename; Session["carga"] = filename; e.DeleteTemporaryData(); }
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.State != AjaxControlToolkit.AjaxFileUploadState.Success) { return; } using (FlightData fd = new FlightData()) { if (fd.ParseFlightData(System.Text.Encoding.UTF8.GetString(e.GetContents()))) { if (fd.HasLatLongInfo) { Coordinates.AddRange(fd.GetTrajectory()); HasTime = HasTime && fd.HasDateTime; HasAlt = HasAlt && fd.HasAltitude; HasSpeed = HasSpeed && fd.HasSpeed; } } else { lblErr.Text = fd.ErrorString; } } e.DeleteTemporaryData(); }
protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file) { // User can save file to File System, database or in session state if(file.ContentType.Contains("jpg") || file.ContentType.Contains("gif") || file.ContentType.Contains("png") || file.ContentType.Contains("jpeg")) { // Limit preview file for file equal or under 4MB only, otherwise when GetContents invoked // System.OutOfMemoryException will thrown if file is too big to be read. if(file.FileSize <= 1024 * 1024 * 4) { Session["fileContentType_" + file.FileId] = file.ContentType; Session["fileContents_" + file.FileId] = file.GetContents(); // Set PostedUrl to preview the uploaded file. file.PostedUrl = string.Format("?preview=1&fileId={0}", file.FileId); } else { file.PostedUrl = "fileTooBig.gif"; } // Since we never call the SaveAs method(), we need to delete the temporary fileß file.DeleteTemporaryData(); } // In a real app, you would call SaveAs() to save the uploaded file somewhere // AjaxFileUpload1.SaveAs(MapPath("~/App_Data/" + file.FileName), true); }
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } if (e.State != AjaxControlToolkit.AjaxFileUploadState.Success) { return; } TimeZoneInfo tz = (TimeZoneInfo)Session[SessionKeyTZ]; TelemetryMatchResult tmr = new TelemetryMatchResult() { TelemetryFileName = e.FileName }; if (tz != null) { tmr.TimeZoneOffset = tz.BaseUtcOffset.TotalHours; } DateTime? dtFallback = null; Regex rDate = new Regex("^(?:19|20)\\d{2}[. _-]?[01]?\\d[. _-]?[012]?\\d", RegexOptions.Compiled); MatchCollection mc = rDate.Matches(e.FileName); if (mc != null && mc.Count > 0 && mc[0].Groups.Count > 0) { DateTime dt; if (DateTime.TryParse(mc[0].Groups[0].Value, out dt)) { dtFallback = dt; tmr.TimeZoneOffset = 0; // do it all in local time. } } tmr.MatchToFlight(System.Text.Encoding.UTF8.GetString(e.GetContents()), Page.User.Identity.Name, dtFallback); Results.Add(tmr); e.DeleteTemporaryData(); }
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.State != AjaxControlToolkit.AjaxFileUploadState.Success) { lblFileRequired.Text = Resources.LogbookEntry.errImportInvalidCSVFile; SetWizardStep(wsUpload); return; } Session[szSessFile] = e.GetContents(); e.DeleteTemporaryData(); // Now we wait for the force refresh }
void XhrDone(string fileId) { AjaxFileUploadEventArgs args; var tempFolder = GetTempFolder(fileId); if (!Directory.Exists(tempFolder)) { return; } var files = Directory.GetFiles(tempFolder); if (files.Length == 0) { return; } var fileInfo = new FileInfo(files[0]); CheckTempFilePath(fileInfo.FullName); SetUploadedFilePath(fileInfo.FullName); var originalFilename = StripTempFileExtension(fileInfo.Name); args = new AjaxFileUploadEventArgs( fileId, AjaxFileUploadState.Success, "Success", originalFilename, (int)fileInfo.Length, Path.GetExtension(originalFilename)); if (UploadComplete != null) { UploadComplete(Control, args); } args.DeleteTemporaryData(); Response.Write(new JavaScriptSerializer().Serialize(args)); }