Skip to content

Instantly share code, notes, and snippets.

View gpapadopoulos's full-sized avatar

George Papadopoulos gpapadopoulos

View GitHub Profile
@gpapadopoulos
gpapadopoulos / DownloadResponseAsAFile.cs
Created October 19, 2015 06:19
Get the HTML Form as a Stream: 1st method: if we want to download the HTML as file...
// DONE: Get the HTML Form as a Stream: 1st method: if we want to download the HTML as file...
// Set the response to "HttpResponseMessage" in order to allow the user to download the file through his browser
var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(stream) };
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "ATTUNITY-LOGON.TXT" };
@gpapadopoulos
gpapadopoulos / UploadFilesToAttunity
Last active October 16, 2015 10:57
UploadFilesToAttunity
/// <summary>
/// DONE: PICK UP FILES FROM "UPLOADS_TEMP_DIR" AND UPLOAD THEM TO ATTUNITY
/// TODO: SHOULD MOVE THIS METHOD TO "DLSFileUtils" CLASS.
/// </summary>
/// <param name="applicationId"></param>
/// <returns></returns>
public void UploadFilesToAttunity(string applicationId)
{
// DONE: "UPLOADS_TEMP_DIR" IN SystemConfiguration TABLE - "SystemConfiguration.getConfigValue("UPLOADS_TEMP_DIR", true)" - "C:/SERVER_FILES/"
string basePath = SystemConfiguration.getConfigValue("UPLOADS_TEMP_DIR", true);
@gpapadopoulos
gpapadopoulos / UploadFile Method
Last active October 15, 2015 06:27
ApplicationController.UploadFile() - WebAPI
[HttpPost]
public async Task<IHttpActionResult> UploadFile()
{
try
{
if (!Request.Content.IsMimeMultipartContent())
Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
#region PREVIOUS CODE - UPLOADS THE FILES TO A SERVER-SIDE DIRECTORY
@gpapadopoulos
gpapadopoulos / Cryptography.cs
Last active October 13, 2015 06:58
Sample Cryptography class which provides EncryptString() and DecryptString() methods that allow you to Encrypt a SecureString into a String object and conversely, Decrypt a String into a SecureString.
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
namespace DLSJobScheduler.BusinessLogic
{
class Cryptography
{
@gpapadopoulos
gpapadopoulos / ReadAsStreamAsync-Example.cs
Created October 13, 2015 06:50
How to get the Stream of a file from a Request object using "Request.Content.ReadAsStreamAsync()"
#region TEST "Request.Content.ReadAsStreamAsync()"
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
foreach (var item in provider.Contents.Where(item => item.Headers.ContentDisposition.FileName != null))
{
Stream streamRead = await item.ReadAsStreamAsync();