I'm going to build website that uses the translation service from Microsoft. I need to get all the available translations for each word but the code I have provides only one translation while it is supposed to give all available translations. Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using microsofttranslator;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel;
using TranslatorService;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{string Appid="my Appid";
string t="any text";
microsofttranslator.TranslateOptions options = new microsofttranslator.TranslateOptions();
options.Category = "general";
options.ContentType = "text/plain";
options.User = "TestUserId";
options.Uri = "";
bool a=true;
SoapService s = new SoapService();
microsofttranslator.GetTranslationsResponse translations = s.GetTranslations(Appid, t, "ar", "en", 5,a, options);
Response.Write(string.Format("Available translations for source text '{0}' are", t));
foreach (microsofttranslator.TranslationMatch translationMatch in translations.Translations)
{
Response.Write(string.Format("Translated text: {0}" + Environment.NewLine + " Rating:{1}" + Environment.NewLine + "Count:{2}" + Environment.NewLine, translationMatch.TranslatedText, translationMatch.Rating.ToString(), translationMatch.Count.ToString()));
} }}
I added Microsft translate WSDL as a web reference http://api.microsofttranslator.com/v2/Soap.svc?wsdl and I added TranslatorService as a service reference http://api.microsofttranslator.com/V2/Soap.svc
This code works well but as I said it gives only one translation while it is supposed to give all the available translations of a word. I cannot figure out what I am doing wrong.
Maybe you should use the "translateArray" method.
http://msdn.microsoft.com/en-us/library/ff512438.aspx
Related
I want to make this really simple. I have a fresh, brand new asp.net C# web form with the code behind showing as below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
I have a SharePoint 2013 site with a document library that has a few documents in it with a few columns of metadata.
How do I make it show on the web page, a link to each document and the metadata from the columns for each document from the library. I'm super new to any work with integrating SharePoint and ASP.Net.
Please help.
Andy
Sharepoint has 3 APIs that you could use. Have a look here: https://msdn.microsoft.com/en-us/library/office/jj164060.aspx
You probably want to use the client.svc service via the CSOM Library (Microsoft.SharePoint.Client) just because it is the easiest to get up and running on. Don't use the older asmx api because it is deprecated. There's a third option - REST - but it doesn't provide all the functionality that CSOM does.
Here's some rough code showing the basics. There are a lot of nuances that aren't covered in the code (SharePoint is complicated) so you you'll also want to find some additional information online.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Client;
public partial class _Default : System.Web.UI.Page
{
protected string SiteUrl = "http://mysite.mydomain.com/site";
protected string LibraryName = "MyList";
protected void Page_Load(object sender, EventArgs e)
{
var context = new ClientContext(SiteUrl);
context.Load(context.Site);
context.ExecuteQuery();
var list = context.Web.Lists.GetByTitle(LibraryName);
if (list == null)
{
throw new ArgumentException(string.Format("List with name '{0}' not found on site '{1}'", LibraryName, SiteUrl));
}
context.Load(list, l => l.RootFolder.ServerRelativeUrl);
context.ExecuteQuery();
// Empty query. You probably want to filter on something so
// do a search on "CAML Query". Also watch out for SharePoint
// List View Threshold which limits # of items that can be retrieved
var camlQuery = #"<View Scope='All'><Query></Query></View>";
var items = list.GetItems(camlQuery);
context.Load(items, l => l.IncludeWithDefaultProperties(i => i.Folder, i => i.File, i => i.DisplayName));
context.ExecuteQuery();
// Url for first item
var url = SiteUrl + "/" + LibraryName + "/" + items[0]["Title"]
}
}
I created a class for connection and using with register.aspx without any problem. When i try to move codes from register.aspx.cs to regpartial.cs then i get an conflict error: "connection conn = new connection();"
I would like to move codes register.aspx.cs to mypartial.cs. I think it will be better but i'm not sure how can i solve conflict problem.
Register.aspx.cs (final)
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using test.App_Code;
namespace test
{
public partial class register: System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs e)
{
}
Connection.cs (final try)
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
namespace test.App_Code
{
public class connection
{
public SqlConnection connect()
{
SqlConnection conn= new SqlConnection("Data Source=******;Initial Catalog=****;Integrated Security=False;User Id=****;Password=*****;MultipleActiveResultSets=True");
baglanti.Open();
return (conn);
}
}
regpartial.cs (Final try)
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test.App_Code.partials
{
connection conn = new connection();
public partial class regpartial : register
{
}
}
In general you shouldn't have much code inside your aspx.cs files.
You want to separate the logic that is directly your view/presentation logic (stuff that makes the .aspx pages work) from your business logic (sequencing, transformation, validation), and finally you want to have your Data Access / Resource Access to be isolated.
I'd also recommend using Dapper.NET over raw ADO.NET/SqlConnection.
I'm going to string together a very basic example of how you can separate this. This is not guaranteed to compile c# code but it will very close pseudocode.
Inside registration.aspx.cs
private void btnRegister_Click(object sender, EventArgs e)
{
var email = txtEmail.Text;
var password = txtPassword.Text;
var registration = new Registration { Email = email, Password = password }
var bizService = new RegistrationService();
var response = bizService.Register(registration);
if(response.Success) Response.Redirect("~/registration/success");
ltlError.Text = response.FailureMessage;
}
RegistrationService.cs
public class RegistrationService {
public RegistrationResponse Register(Registration req)
{
var regDAL = new RegistrationAccess();
var isEmailDuplicated = regDal.DoesEmailExist(req.Email)
if(isEmailDuplicated)
return new RegistrationResponse {
Success = false,
FailureMessage = "Email exists, did you mean to login instead?
}
regDAL.InsertNewRegistration(req)
return new RegistrationResponse { Success = true };
}
}
Lastly you should have a RegistrationAccess.cs that contains only code for reading and writing to SQL Server / other database / file system.
Note how the aspx.cs file has no knowledge of RegistrationAccess. Your view should not be directly calling the database. The other thing to note is that RegistrationService has no knowledge of the view. It receives a Registration type, then executes business logic and calls out to the DAL. The DAL class will have zero knowledge of both the view and the RegistrationService, it will know only one thing, the database.
This is the basis of a very simple ASP.NET webforms solution. A better solution would use the MVP/MVVM patterns and the Dependency Inversion Principle but those aren't worth using if you don't understand basic separation of concerns yet.
I am working in project in which I have used vlc plugin v2. the path for my video is
axVLC.playlist.add(#"D:\My Project\Science\Resources\myvideo.mp4");
axVLC.playlist.play();
now the problem is when I build the project and give it to someone and he/she install it on his/her computer , it show exception that video path is wrong. I am sure that path is not suitable as my the video path in my project is D:... and he/she installed it on C.
So my question is that is there any way to give it common path by which user don`t face such kind of error
Import IO
Using System.IO;
then declare a string that will reference to your video folder
string AbsoluteRef;
use this code in your form load
if (System.Diagnostics.Debugger.IsAttached)
{
AbsoluteRef = Path.GetFullPath(Application.StartupPath + "\\..\\..\\Resources\\");
}
else
{
AbsoluteRef = Application.StartupPath + "\\Resources\\";
}
Now declare a string for your video or which ever file like
string vlcvideo;
now add the two together
vlcvideo = AbsoluteRef & "myvideo.mp4";
Finnally add all this into your vlc plugin
axVLC.playlist.add(vlcvideo);
Complete Code looks like so.
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Input;
using yournamespace.Forms;
using System.IO;
namespace yourNameSpace
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
string AbsoluteRef = null;
private void frmMain_Load(object sender, EventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
AbsoluteRef = Path.GetFullPath(Application.StartupPath + "\\..\\..\\Resources\\");
}
else
{
AbsoluteRef = Application.StartupPath + "\\Resources\\";
}
string vlcVideo = AbsoluteRef + "myvideo.mp4";
axVLC.playlist.add(vlcvideo);
}
i Keep getting this error message and can't figure out why?
Compiler Error Message: CS1513: } expected
here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void gettickvalue(object sender, EventArgs e)
{
Random RandomNumber = new Random();
int n = RandomNumber.Next(1, 9);
imgBanner.ImageUrl = System.String.Concat("Timer/banner_", n.ToString(), ".jpg");
}
If what you posted is your whole class, you're missing a curly brace. Exactly as the error message says.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void gettickvalue(object sender, EventArgs e)
{
Random RandomNumber = new Random();
int n = RandomNumber.Next(1, 9);
imgBanner.ImageUrl = String.Concat("Timer/banner_", n.ToString(), ".jpg");
}
} //we added this curly brace
It's easier to see where it's missing if you format your code properly. Visual Studio can do this for you, look it up to see how in your version. I'm on Visual Studio 2010 Pro, so I go to Edit -> Advanced -> Format Document.
Notice also that I changed your concatenation function to just be String.Concat instead of System.String.Concat. No need to put the system reference in front of it because the namespace is already referenced by your first using statement.
I also suggest you rename your function. See General Naming Conventions on MSDN.
I am currently making a .NET application which allows the user to upload an audio file and convert it into an mp3. I am using FFmpeg. It works with .wav and .mp3, but the application returns a "connection was reset" (I use Firefox 4 for testing) when I try to upload formats like .wma or .m4a. Naturally, when I was testing for errors by uploading unsupported files like .jpg it also returned the same thing. The command line argument worked as intended when I did it using cmd.
Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Media;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Text.RegularExpressions;
namespace AudioConvert
{
public partial class _Default : System.Web.UI.Page
{
Process ffmpeg;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpload_Click(object sender, EventArgs e)
{
string audio;
string mp3;
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(#"\Temp\"+FileUpload1.FileName);
}
//FileUpload1.SaveAs(Server.MapPath("") + System.IO.Path.GetFileName(FileUpload1.FileName));
audio = #"\Temp\"+FileUpload1.FileName; //audio filepath
mp3 = Page.MapPath("") + "\\Media\\"+FileUpload1.FileName+".mp3";
ffmpeg = new Process();
try
{
ffmpeg.StartInfo.Arguments = "-y -i \"" + audio + "\" -ab 128k \"" + mp3; //-command line argument, overwrites automatically
ffmpeg.StartInfo.FileName = Page.MapPath("ffmpeg.exe"); //ffmpeg file location
ffmpeg.Start();
ffmpeg.WaitForExit();
ffmpeg.Close();
}
catch
{
}
}
}
}