After searching around here for over two hours, I still can't get the code I pieced together from here to work due to a missing reference I believe.
The error I am getting is from the part below in which Request does not exist in the current context.
return Request.CreateResponse(HttpStatusCode.BadRequest);
Another error I am getting is that getFileFromID also does not exist in the current context.
getFileFromID(id, out fileName, out fileSize);
I'm sure it's just a simple reference I am missing but I've tried googling and still can't find the solution. Does anyone know why I keep getting the "does not exist in the current context" error?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Morningstar.JSON;
using Ionic.Zip;
using System.Net;
using System.IO.Compression;
using System.Windows.Forms;
using Ionic.Zip;
using System.Web;
using System.Net.Http;
using System.Web.Http;
namespace MS_Hourly_API_Call
{
class Program
{
public static void Main(string[] args)
{
// THIS ONE IS DIFFERENT FROM THE ORIGINAL DOWNLOADCURVEDATA
string feedName = "RiskReporting_Power_Hub_Hourly";
var url = String.Format("https://mp.morningstarcommodity.com/lds/lists/{0}/content?fromDateTime={1}", feedName, DateTime.Today.ToString("yyyy-MM-dd"));
string username = "asdfk"; //removed username
string password = "asdfasdf"; //removed password
// Setup web connection with appropriate authentication parameters and requesting a JSON response
using (var syncClient = new WebClient())
{
syncClient.Headers.Add("Accept", "application/json");
syncClient.Credentials = new NetworkCredential(username, password);
// Retrieve and parse the JSON response
var jsonContent = syncClient.DownloadString(url);
var feedItems = JsonConvert.DeserializeObject<List<FeedContent>>(jsonContent);
// Download each item
syncClient.Headers.Remove("Accept");
}
}
public HttpResponseMessage GetFile(string id)
{
if (String.IsNullOrEmpty(id))
return Request.CreateResponse(HttpStatusCode.BadRequest);
string fileName;
string localFilePath;
int fileSize;
localFilePath = getFileFromID(id, out fileName, out fileSize);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = fileName;
return response;
}
}
}
Requestto be? My guess is that you're actually trying to call this method but you're missing the fact that in the context you originally saw the code in, there was aRequestproperty...Requestproperty is accessible from web project types.