I am not able to play the mp3 file in telerik rad media player.
Here is my try:
string filePath =Server.MapPath("~/App_Temp/") + "test.mp3";
if (testAudios != null)
{
byte[] bytes =Convert.FromBase64String(testAudios.FirstOrDefault().reAudio);
using (var audioFile = new FileStream(filePath, FileMode.Create))
{
audioFile.Write(bytes, 0, bytes.Length);
audioFile.Flush();
}
}
var file = new MediaPlayerAudioFile() { Title = "RESPONSE AUDIO" };
file.Sources.Add(new MediaPlayerSource()
{ Path = filePath, MimeType = "audio/mpeg" });
player.Playlist.Add(file);
this code is not working. I have checked the path, it's working. I have tried the same path with html directly. Its working successfully.
My html try is:
<telerik:RadMediaPlayer ID="player" runat="server" Width="320px" BackColor="Black"
StartVolume="80" Height="200px">
<Sources>
<telerik:MediaPlayerSource Path="~/App_Temp/test.mp3" />
</Sources>
</telerik:RadMediaPlayer>
It looks like the Path string filePath =Server.MapPath("~/App_Temp/") + "test.mp3"; you specified here isn't exactly suitable for the RadMediaPlayer in the code behind.
Try changing to a relative path should make it work for you. Something like below
var filePath = Page.ResolveUrl("~/App_Temp/test.mp3");
var file = new MediaPlayerAudioFile() { Title = "RESPONSE AUDIO" };
file.Sources.Add(new MediaPlayerSource() { Path = filePath, MimeType = "audio/mpeg", });
player.Sources.Clear();
player.AutoPlay = false;
player.Playlist.Add(file);
Hope it helps
Related
I save images relative to the workingdirectory and then want to display them in a uno Skia.WPF app.
However they never appear.
This is how I create the ImageSource:
public static async Task<ImageSource> GenerateSource()
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.FileTypeFilter.Add(".png");
var pickerResult = await picker.PickSingleFileAsync("tileset");
if (pickerResult is null)
return null;
using var stream = await pickerResult.OpenReadAsync();
string imagePath = Path.GetFullPath(Path.Combine("cache", "image.png"));
Directory.CreateDirectory(Path.GetDirectoryName(imagePath));
using (var bitmapImageStream = File.Open(imagePath,
FileMode.Create,
FileAccess.Write,
FileShare.None))
{
await stream.AsStreamForRead().CopyToAsync(bitmapImageStream);
bitmapImageStream.Flush(true);
}
var imgSrc = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
imgSrc.UriSource = new Uri($"file://{imagePath}");
var width = imgSrc.PixelHeight;
return imgSrc;
}
But when I use the path directly in the Xaml it also not working.
<Image Source="file://cache/image.png" Width="32" Height="32" />
Using an image from the Internet using an http url works.
Sample Repo
file: URIs are currently not supported in Uno, however, you can still show local images by copying to the appropriate folder using ms-appdata scheme. If you copy the file into ApplicationData.Current.TemporaryFolder, you will the be able to reference that path by ms-appdata:///temp/{imageName} URI.
My objective is User can choose an image from any place from their desktop and upload/tweet the same to twitter. I'm struggling to set the relative path to the imagePath variable.
The path (D Drive) were my image stored. While running the application it looks in different path. This throws an error System.IO.FileNotFoundException. I tried Server.MapPath too. Assist me to resolve it.
Solved the issue as following
string filePath; string imagePath = "";
if (imgFile == null)
{
imgFile = Request.Files["imgFile"];
}
if (imgFile.FileName != "")
{
filePath = Server.MapPath("~/Images/");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
filePath = filePath + Path.GetFileName(imgFile.FileName);
imgFile.SaveAs(filePath);
imagePath = Path.Combine(Server.MapPath(#"~/Images/"), filePath);
}
File must be saved in the server location, try to replace the below instruction:
string imagePath=Path.Combine(Request.MapPath("~/"),fileName);
with the below instruction
var fileName = Path.GetFileName(file.FileName);
var imagePath = Path.Combine(Request.MapPath("~/"), fileName);
file.SaveAs(imagePath);
........
Cordially
I have a arrav string like this:
string[] imgList = new[] { "/Images/10000489Back20130827.jpg", "/Images/2F.jpg", "/Images/10000489Front20130827.jpg" };
that contain names of file, contained in an virtaul directory.
If this parameteres I assigned to an ImageUrl, the image is displayed. In the detail of the pages show the propertie like this:
src="/Images/1F.jpg"
But when I try to looking for the files in specific directory all the files and assigned to an ImageUrl rpoperties, the images it's not displayed. I note that the path retrieve complete, and not a reference of the virtaul directory
string path = "/Images"; ///Obtener el path virtual
DirectoryInfo directory = new DirectoryInfo(path);
FileInfo[] files = directory.GetFiles("*.jpg");
imgList = files.Where(x => x.FullName.Contains(clientNumber)).Select(x => x.FullName).ToList().ToArray();
I retrieve this path:
src="C:/Images/1F.jpg"
How can I get only the virtual path with the name of the file using DirectoryInfo class?
try this:
string path = "/Images";
DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath(path));
I resolved it:
Instead to pass the full path:
x.FullName
I concatenate the virtual path with the file name.
path + x.Name
Example
imgList = files.Where(x => x.FullName.Contains(clientNumber)).Select(x => path + x.Name).ToList().ToArray();
Show Image In Virtual Path Like (C:\Users\User\Desktop\Signature.png) : Its Working
I used Try Catch To Avoid Error
Cliend Side :
asp:Image runat="server" ID="Image1" />
Server Side :
try
{
Byte[] bytes = System.IO.File.ReadAllBytes(#"C:\Users\User\Desktop\Signature.png");
Image1.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.Visible = true;
}
catch (Exception e)
{
}
How to set image tag source from reading the key from AppSettings section in web.config in html file.
I am using one html file, in which there is an image tag and I want to set image source from web.config file key.
The web.config key is: <add key="Image" value="Image.gif" />
But i am not able to set the key on source.
I have tried this :
<img src="<%= ConfigurationSettings.AppSettings["Image"] %>" width="685" height="177" />
but is not reading the source from there.
Based on your comments, it looks like you're trying to generate a html file to be sent via email. Your better off creating a html file with place holders for the information you want to inject. Use a text reader to read the html from the file, and use regex or string.replace on the text replacing the place holders for the actual values.
You will need to have a full URL to images.
e.g.
To read the HTML
var HTML = EmailTemplate.GetHTMLFromTemplate(path to template)
public static string GetHTMLFromTemplate(string templatepath)
{
var TemplateBody = new StringBuilder();
using (var Reader = new StreamReader(templatepath))
{
string Line;
while ((Line = Reader.ReadLine()) != null)
{
TemplateBody.Append(Line);
}
}
return TemplateBody.ToString();
}
Then replace the parts of the html
String.Replace("[image placeholder]", ConfigurationManager.AppSettings["Image"]);
The Email Template class looks like this (this is very old code!!)
public class EmailTemplate
{
public string Body { get; private set; }
public static EmailTemplate GetTemplate(string body, string url, string html)
{
var AmendedHTML = new StringBuilder(html);
AmendedHTML.Replace("[body]", body);
AmendedHTML.Replace("../images", url + "images");
var MyEmailTemplate = new EmailTemplate { Body = AmendedHTML.ToString() };
return MyEmailTemplate;
}
public static EmailTemplate GetTemplate(string body, string title, string url, string year, string html)
{
var AmendedHTML = new StringBuilder(html);
AmendedHTML.Replace("[BODY]", body);
AmendedHTML.Replace("[HEADING]", title);
AmendedHTML.Replace("../images", url + "images");
AmendedHTML.Replace("[DATE]", year);
AmendedHTML.Replace("[contactus.aspx]", url + "contactus/index.aspx");
AmendedHTML.Replace("[unsubscribe.aspx]", url + "register/unsubscribe.aspx");
var MyEmailTemplate = new EmailTemplate { Body = AmendedHTML.ToString() };
return MyEmailTemplate;
}
public static string GetHTMLFromTemplate(string path)
{
var TemplateBody = new StringBuilder();
using (var Reader = new StreamReader(path))
{
string Line;
while ((Line = Reader.ReadLine()) != null)
{
TemplateBody.Append(Line);
}
}
return TemplateBody.ToString();
}
}
try this: <img src="<%= System.Web.Configuration.WebConfigurationManager.AppSettings["Image"].ToString() %>" width="685" height="177" />
You want to replace a value in your .html email template.
You can do that by reading the file into memory, and replace a placeholder in your .html file.
Change the image tag to something like
<img src="$$image$$" width="685" height="177" />
Then in your code
string myString = "";
using (StreamReader reader = new StreamReader(Server.MapPath("~/Email/Product/<nameofthepage>.html"))) {
myString = reader.ReadToEnd();
}
myString = myString.Replace("$$image$$", ConfigurationSettings.AppSettings["Image"]);
then set the body property of your mail to myString
I am using the below code to Upload an Image file to a SharePoint Document Library. The code works fine locally but once deployed to server, i get the Exception as file not found.
String fileToUpload = FlUpldImage.PostedFile.FileName; //#"C:\Users\admin.RSS\Desktop\Photos\me_skype.jpg";
String documentLibraryName = "SiteAssets";
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File not found.", fileToUpload);
SPFolder myLibrary = web.Folders[documentLibraryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = CheckStringNull(txtFirstName.Text) + CheckStringNull(txtLastName.Text) + CheckDateNull(txtDOB) + System.IO.Path.GetFileName(fileToUpload); ;
if (fileName.Contains('/'))
{
fileName = fileName.Replace("/", "");
}
if (fileName.Contains(':'))
{
fileName = fileName.Replace(":", "");
}
FileStream fileStream = File.OpenRead(fileToUpload);
//Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
string url = site.ToString() + "/" + spfile.ToString();
if (url.Contains("="))
{
url = url.Split('=')[1];
}
//Commit
myLibrary.Update();
The string fileupload contains URL as C:\Users\admin.RSS\Desktop\Photos\me.jpg This URL is actually the client system and the server side code throws exception as file not found. How to handle this issue?
UPDATE:
I removed the lines of code that checks if the file exists and now i get the exeption on FileStream fileStream = File.OpenRead(fileToUpload); as c:\windows\system32\inetsrv\20120605_133145.jpg cold not be found
Kindly help. Thank You
if (this.fuAvatarUpload.HasFile && this.fuAvatarUpload.PostedFile.FileName.Length > 0)
{
string extension = Path.GetExtension(file.FileName).ToLower();
string mimetype;
switch (extension)
{
case ".png":
case ".jpg":
case ".gif":
mimetype = file.ContentType;
break;
default:
_model.ShowMessage("We only accept .png, .jpg, and .gif!");
return;
}
if (file.ContentLength / 1000 < 1000)
{
Image image = Image.FromStream(file.InputStream);
Bitmap resized = new Bitmap(image, 150, 150);
byte[] byteArr = new byte[file.InputStream.Length];
using (MemoryStream stream = new MemoryStream())
{
resized.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byteArr = stream.ToArray();
}
file.InputStream.Read(byteArr, 0, byteArr.Length);
profile.ImageUrl = byteArr;
profile.UseGravatar = false;
profileService.UpdateProfile(profile);
this._model.ShowApprovePanel();
}
else
{
_model.ShowMessage("The file you uploaded is larger than the 1mb limit. Please reduce the size of your file and try again.");
}
}
Saving the file physically onto server and than working on the same helped me resolve my issue.