public async Task <IActionResult> OnPostAsync(int fsoId, int returnId) { if (!ModelState.IsValid) { return(Page()); } User FromUser = await _context.Users.FirstOrDefaultAsync(p => p.UserAccountId == _userManager.GetUserId(User)); FileSystemObject fso = await _context.FileSystemObjects.FirstOrDefaultAsync(f => f.Id == fsoId); PublicFile newPublicFile = new PublicFile(); newPublicFile.FromUserId = FromUser.Id; newPublicFile.FsoId = fsoId; newPublicFile.SharedDate = DateTime.Now; newPublicFile.PublicId = CreateMD5(fso.Name); try { _context.PublicFiles.Add(newPublicFile); await _context.SaveChangesAsync(); } catch (Exception ex) { return(RedirectToPage("HomePage", new { id = returnId })); } return(RedirectToPage("Public", new { id = newPublicFile.PublicId })); }
public async Task <IActionResult> OnGetAsync(string?id) { if (id != null) { PubFile = await _context.PublicFiles.FirstOrDefaultAsync(p => p.PublicId == id); PubFile.FromUser = await _context.Users.FirstOrDefaultAsync(u => u.Id == PubFile.FromUserId); PubFile.Fso = await _context.FileSystemObjects.FirstOrDefaultAsync(f => f.Id == PubFile.FsoId); return(Page()); } else { return(RedirectToPage("Index")); } }
private async void button1_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { filePath = openFileDialog.FileName; lbl_msg.Content = "new file was selected: " + filePath; } string[] tokens = openFileDialog.FileName.Split('\\'); int cnt = tokens.Length; Console.WriteLine(tokens[cnt - 1]); byte[] binary = File.ReadAllBytes(filePath); Console.WriteLine(binary[2]); PublicFile p = new PublicFile(); p.fileId = 0; p.fileName = tokens[cnt - 1]; p.publishDate = new LocalDate(2018, 1, 23); p.publisherTeacher = new Teacher("Admin1234", "Admin1234"); p.fileContent = binary; Console.WriteLine(p.fileContent.ToString()); var jsonString = new JavaScriptSerializer().Serialize(p); //var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(p); var response = await client.PostAsync(@"http://192.168.195.165:8080/WebServiceSchoopy/webresources/publicfiles", new StringContent(jsonString, Encoding.UTF8, "application/json")); var responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseString); init(); }
private void button2_Click(object sender, RoutedEventArgs e) { try { PublicFile p = (PublicFile)listBox.SelectedItem; if (p == null) { throw new Exception("Please select a file!"); } string json = (c.Get(@"http://192.168.195.165:8080/WebServiceSchoopy/webresources/publicfiles/" + p.fileId)); PublicFile deserializedPublicFile = new JavaScriptSerializer().Deserialize <PublicFile>(json); Blob b = new Blob(deserializedPublicFile.fileName, deserializedPublicFile.fileContent); SaveFileDialog sfDialog = new SaveFileDialog(); string tempfile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + System.IO.Path.GetExtension(b.FileName); File.WriteAllBytes(tempfile, deserializedPublicFile.fileContent); Process.Start(tempfile); }catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary>Returns a hash code for this keyring.</summary> public override int GetHashCode() { return PublicFile.GetHashCode(); }