For some reason the text below, once ran through the action below creates a straight line, instead of taking into account the new line characters (\n). Are they being stripped out with the FileContentResult or GetBytes, and if so can I fix this?
"<div id=\"exp-schedule-93943\" data-href=\"https://localhost:2222/widgets/v1/schedule?eventid=93943\" data-responsive=\"true\" data-protocol=\"https\" data-width=\"100%\" data-height=\"500px\"></div>\n<script type=\"text/javascript\">\n (function (d, s, id) {\n var js, fjs = d.getElementsByTagName(s)[0];\n if (!d.getElementById(id)) {\n js = d.createElement(s);\n js.id = id;\n js.async = true;\n js.src = \"https://localhost:2222/scripts/exposure.widgets.min.js\";\n fjs.parentNode.insertBefore(js, fjs);\n }\n })(document, \"script\", \"exp.widgets\");\n</script>"
Controller Action
public virtual ActionResult Download(string text, string fileName)
{
var contentDisposition = new ContentDisposition
{
FileName = fileName,
Inline = false,
};
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(Encoding.UTF8.GetBytes(text), "text/plain");
}
Text.txt
<div id="exp-events-19185" data-href="https://basketball.exposureevents.com/widgets/v1/events?organizationid=19185" data-css="https://cdn.exposureevents.com/content/external/bballshowcase.min.css" data-responsive="true" data-protocol="https" data-width="100%" data-height="500px"></div><script type="text/javascript"> (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.async = true; js.src = "https://basketball.exposureevents.com/scripts/exposure.widgets.min.js"; fjs.parentNode.insertBefore(js, fjs); } })(document, "script", "exp.widgets");</script>
Related
string? folder = _dirSettings.PostImageDir;
List<PostImage> postImages = new();
if (!string.IsNullOrEmpty(folder))
{
string[] folderPaths = folder.Split("/");
string[] fileExtentions = new[]{
".pdf",
".png",
".jpeg",
"jpg"
};
await using ApplicationDbContext dbContext =
_dbContextFactory.CreateDbContext();
foreach (var file in files)
{
string fileName = System.IO.Path.GetFileNameWithoutExtension(file.Name);
string fileExtn = System.IO.Path.GetExtension(file.Name);
if(!fileExtentions.Contains(fileExtn))
{
throw new Exception("only Can Add pdf, png, jpeg, jpg");
}
var postImage = new PostImage()
{
Title = fileName,
ImageUri = new Uri(new Uri("file://"),folder + "/" + Guid.NewGuid().ToString() + "_" + file.Name),
PostId = postId
};
string serverFolderPath = _webHostEnvironment.ContentRootPath;
foreach (var path in folderPaths)
{
serverFolderPath = System.IO.Path.Combine(serverFolderPath, path);
}
using (var fileStream = new FileStream(serverFolderPath, FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
postImages.Add(postImage);
}
await dbContext.AddRangeAsync(postImages);
await dbContext.SaveChangesAsync();
when I run this code it show Access to the path 'D:\Web\GraphQL\Files\PostImages' is denied.
I already Added all permission to Users. and unchecked readonly to folder.
how can I fix it? thank you.
I'm struggling to convert vine api code in asp.net,that i found from here ,any one have any idea?
Its really appreciate if any one know how to convert this curl to asp.net
class Vine {
private static $base_url = "https://api.vineapp.com";
private static $referer = "api.vineapp.com";
private static $vine_session = null;
private static $vine_id = null;
public static function login($username, $password) {
$success = false;
$url = self::$base_url . "/users/authenticate";
$curl = new Curl;
$response = json_decode($curl->post($url, array('username'=>$username, 'password'=>$password)));
if(isset($response->success) and $response->success) {
self::$vine_session = $response->data->key;
self::$vine_id = $response->data->key;
$success = true;
}
return $success;
}
public static function get_tag($tag) {
$encoded_tag = urlencode($tag);
$url = self::$base_url . "/timelines/tags/$encoded_tag";
$payload = null;
$curl = new Curl;
if(self::$vine_session) {
$curl->headers['vine-session-id'] = self::$vine_session;
}
$response = json_decode($curl->get($url));
if(isset($response->success) and $response->success) {
$payload = $response->data->records;
}
return $payload;
}
}
Finally I succeeded to get feed from vine using C#.Find bellow code to
do this stuff.
string data = "username=yourusername&password=password"; //replace <value>
byte[] dataStream = Encoding.UTF8.GetBytes(data);
string urlPath = "https://api.vineapp.com/users/authenticate";
string request = urlPath;
WebRequest webRequest = WebRequest.Create(request);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = dataStream.Length;
Stream newStream = webRequest.GetRequestStream();
// Send the data.
newStream.Write(dataStream, 0, dataStream.Length);
newStream.Close();
WebResponse webResponse = webRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string responseFromServer = reader.ReadToEnd();
JObject js1 = JObject.Parse(responseFromServer);
string key=js1["data"]["key"].ToString();
//GetVineUsers();
string URL = "https://api.vineapp.com/users/search/"+txtName.Text;
var webClient = new WebClient();
webClient.Headers.Add("user-agent", "com.vine.iphone/1.0.3 (unknown, iPhone OS 6.0.1, iPhone, Scale/2.000000)");
webClient.Headers.Add("vine-session-id", key);
webClient.Headers.Add("accept-language", "en, sv, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8");
var json = webClient.DownloadString(URL);
JObject js = JObject.Parse(json);
for (int i = 0; i < 19; i++)
{
FbUser cls = new FbUser();
cls.Id = js["data"]["records"][i]["userId"].ToString();
cls.Name = js["data"]["records"][i]["username"].ToString();
cls.MediaName = "Vine";
listFbUsers.Add(cls);
}
this is my javascript code :
var fileURL = "file://" + mFileListURL[0].fullPath;
var options = new FileUploadOptions();
options.fileKey = "recFile";
var imagefilename = Number(new Date()) + ".jpg";
options.fileName = imagefilename;
options.mimeType = "image/jpeg";
var params = new Object();
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURL,"http://mywebserver/UploadFoto.asmx/SaveImage",
function(r) {
alert("It's OK!");
alert("Response = " + r.response);
}, function(error) {
alert("An error has occurred: Code = "
+ error.code);
}, options);
and this server side code:
[WebMethod]
[GenerateScriptType(typeof(String))]
[ScriptMethod]
public String SaveImage()
{
HttpContext context = HttpContext.Current;
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach (string key in files)
{
HttpPostedFile file = files[key];
string fileName = file.FileName;
if (fileName != null && fileName != "")
{
String fileStored = System.IO.Path.Combine(context.Server.MapPath("~/public/"), fileName);
file.SaveAs(fileStored);
}
}
}
return "Filestored OK";
}
Now, image upload is done but I get no returned string, no response from server, no error code. I used Json response also but nothing (image is upload, no response, no string returned).
What's wrong?
Thanks. IngD
try this
function(r)
{
alert("It's OK!");
alert("Sent = " + r.bytesSent);
}
WebMethod Must be static
[WebMethod]
[GenerateScriptType(typeof(String))]
[ScriptMethod]
public static String SaveImage()
{
HttpContext context = HttpContext.Current;
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach (string key in files)
{
HttpPostedFile file = files[key];
string fileName = file.FileName;
if (fileName != null && fileName != "")
{
String fileStored = System.IO.Path.Combine(context.Server.MapPath("~/public/"), fileName);
file.SaveAs(fileStored);
}
}
}
return "Filestored OK";
}
I have used the following code to use FB Like on my website...but clicking on like posts this to FB "Jonny likes http://www.site.com" but not the actual url of the page which was liked i.e "www.site.com/reports/1".
I have placed this code in the master file...
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
and this in the respective pages....
<div class="fb-like" data-href="http://citizen.tricedeals.com" data-send="true" data-width="450" data-show-faces="false" data-font="verdana"></div>
You must implement the following Meta Tags information while doing
Like press...
og:title
og:description
og:url
og:image
Code Behind
public class MetaTag
{
public string PageURL { get; set; }
public string TagName { get; set; }
public string MetaTagContent { get; set; }
public string SiteName { get; set; }
}
var fbTitleTag = new MetaTag
{
PageURL = "/",
MetaTagName = "og:title",
SiteName = "Your Site Name",
MetaTagContent = "Your Title"
};
var fbDesc = new MetaTag
{
PageURL = "/",
MetaTagName = "og:description",
SiteName = "Site Name",
MetaTagContent = "Your Description"
};
var fbUrl = new MetaTag
{
PageURL = "/",
MetaTagName = "og:url",
SiteName = "Site Name",
MetaTagContent = "URL"
};
var fbImage = new MetaTag
{
PageURL = "/",
MetaTagName = "og:image",
SiteName = "Site Name",
MetaTagContent = "Image URL"
};
System.Collections.Generic.List<MetaTag> List = new System.Collections.Generic.List<MetaTag>();
List.Add(fbTitleTag);
List.Add(fbDesc);
List.Add(fbUrl);
List.Add(fbImage);
RenderMetaTags(List, "SiteName", strRawUrl, ltMetaTags);
Here ltMetaTags is the Literal control to place in Master page. See bottom of the asnwer.
public static void RenderMetaTags(List<MetaTag> MetaTags, string sitename, string strRawURL, Literal ltlMetaHolders)
{
// ltlMetaHolders.Text = "";
foreach (MetaTag oAgentMetaTag in MetaTags)
{
RenderMetaTagByContentName(ltlMetaHolders, oAgentMetaTag.MetaTagName, oAgentMetaTag.MetaTagContent);
}
}
public static void RenderMetaTagByContentName(Literal ltlMetaHolder, string contentName, string content, bool isProp)
{
var metaTagFromat = isProp ? "<meta property=\"{0}\" content=\"{1}\" />" : "<meta name=\"{0}\" content=\"{1}\" /> ";
ltlMetaHolder.Text += string.Format(metaTagFromat, contentName, content);
}
HTML in Master Page
Following is the Literal in Head tag of Master Page
<asp:Literal ID="ltMetaTags" Mode="Transform" runat="server"></asp:Literal>
I have a Facebook page and want to use the like-box social plugin on it.
https://developers.facebook.com/docs/reference/plugins/like-box/
However my code doesn't want to pull up my page:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like-box" data-href="{pagename}" data-width="292" data-show-faces="true" data-stream="true" data-header="true"></div>