|
I am trying to launch a Google search for a specific string from with my application, and this is all working perfectly, until the search string contains quotes. If there are quotes in the search string, then all the spaces inside the string are removed.
In the debugger, the string looks like this:
http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
But when Google gets it, the URL looks like this:
http://www.google.com/search?hl=en&q="JustForLaughsComedyTour"
If there are no quotes around the search string, then it works perfectly. Running it from the command line doesn't work at all unless I remove the quotes around the search string and place them around the entire command.
The code I am using is here:
System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo(strCmd, strArgs);<br />
pInfo.Verb = "open";<br />
pInfo.ErrorDialog = true;<br />
pInfo.WorkingDirectory = strDir;<br />
System.Diagnostics.Process.Start(pInfo);
I realize that I could probably UrlEncode the string or something, but I am using a generic application launcher thingie that doesn't know anything about the application it is launching - it just calls start on whatever string you pass it. Actually, it is a version of the Visual Studio "External Tools" manager that I wrote[^] as a .NET control, so I don't want it to have to treat URLs differently to standard commands, and I don't want the command to be "IExplore.exe" either. I want it to launch the users default browser based on a URL that I give it.
Does anyone know how to workaround this quoted search string weirdness, without having to resort to a special case to fix it?
Thanks!
|
|
|
|
|
|
fly904 wrote: Replace ' ' with '+'.
I can't, because the code that launches the command doesn't know what sort of command it is. In other words, as far as the launcher knows, these two strings are equivalent and should be treated exactly the same:
http://www.google.co.uk/search?q="Just For Laughs Comedy Tour"
notepad "Just For Laughs Comedy Tour"
Interestingly, if you paste the following command into the Run box in Windows XP it doesn't work either, but if you paste it directly into your browser it works just fine. This leads me to think there's something strange going on inside Windows somwehere.
http://www.google.co.uk/search?q="Just For Laughs Comedy Tour"
And just for laughs, try these too:
firefox http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
iexplore http://www.google.com/search?hl=en&q="Just For Laughs Comedy Tour"
They both work as expected.
|
|
|
|
|
I see your point now after testing it.
The only way I found was to 'double escape' the speech marks.
I just tried this and it worked perfectly after opening in my default browser (firefox).
string searchString = "\\\"Just For Laughs Comedy Tour\\\"";
System.Diagnostics.ProcessStartInfo pInfo = new System.Diagnostics.ProcessStartInfo("http://www.google.co.uk/search?q=" +
searchString.Replace(" ", "+"));
pInfo.Verb = "open";
pInfo.ErrorDialog = true;
System.Diagnostics.Process.Start(pInfo);
There's a part of me which hate's seeing spaces in URL's.
hmmm pie
|
|
|
|
|
I have a webpage displaying some information based on the querystring.
i.e., http://www.mywebsite.com/userdetails.aspx?userid=15510
The issue is, i want to access the information of the user while giving the url as http://www.mywebsite.com/15510
I don't know how to do that.Can anyone suggest how to achieve it?
TIA.
|
|
|
|
|
TWo things
1 - what does this have to do with C#
2 - HTTPHandler.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Bey guys,
i have a little problem, so if you can help me ill thank you...
i built a Sql server using Visual Stuido 2008 ( it created me a file name my_database.sdf ). now i am tring to connect to the sql server i have created,
i using the code below:
public void Connect()
{
this.han = new SqlConnection(@"Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtutorial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB");
Console.WriteLine(this.han.ConnectionString);
try
{
this.han.Open();
}
catch (NullReferenceException e)
{
Console.WriteLine(e);
}
catch (SqlException e)
{
Console.WriteLine(e);
}
}
this is a code in class, the class using this.han to make theconnection, the connection string i have copied from the connection strind i got from VS when i did motify connection -> advance. but for some resons i cant connect
the error i got:
Data Source=C:\Users\יהב\Documents\Visual Studio 2008\Projects\ADOtutorial\ADOtu
torial\my_database.sdf;Persist Security Info=True;Application Name=ConnectDB
System.Data.SqlClient.SqlException: אירעה שגיאה הקשורה לרשת או שגיאה ספציפית למו
פע במהלך יצירת חיבור ל- SQL Server. השרת לא נמצא או שאינו נגיש. ודא כי שם המופע
נכון וכי SQL Server מוגדר לאפשר חיבורים מרוחקים. (provider: ממשקי רשת של SQL, e
rror: 26 - שגיאה באיתור שרת/מופע שצוין)
ב- System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exceptio
n, Boolean breakConnection)
ב- System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateOb
ject stateObj)
ב- System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInterna
lConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boo
lean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection
owningObject)
ב- System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire
, SqlConnection owningObject)
ב- System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String hos
t, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObjec
t, SqlConnectionString connectionOptions, Int64 timerStart)
ב- System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnect
ion owningObject, SqlConnectionString connectionOptions, String newPassword, Boo
lean redirectedUserInstance)
ב- System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIden
tity identity, SqlConnectionString connectionOptions, Object providerInfo, Strin
g newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
ב- System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionO
ptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnectio
n owningConnection)
ב- System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbCon
nection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
ב- System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection ownin
gObject)
ב- System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)
ב- System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owni
ngObject)
ב- System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection o
wningConnection)
ב- System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection o
uterConnection, DbConnectionFactory connectionFactory)
ב- System.Data.SqlClient.SqlConnection.Open()
ב- ADOtutorial.Database_Driver.Connect() ב- C:\Users\יהב\Documents\Visual St
udio 2008\Projects\ADOtutorial\ADOtutorial\Database_Driver.cs:שורה 46
Press any key to continue . . .
google translate for the hebrew there:
There was an error related to the network or specific error Lmo <br />
According to the connection during the creation - SQL Server. Server not found or is not accessible. Verify that the instance name <br />
Correct and that SQL Server is configured to allow remote connections. (provider: Web interface of SQL, e <br />
rror: 26 - Error locating server / instance specified)<br />
hope you can help me, thanks, Yahav
Gindi Bar Yahav - Web & Software defeloper.
|
|
|
|
|
.sdf files are SQL CE databases, not SQL Server. You have created an "embedded" database. The database that you wanted (SQL Server) has the file-extension ".mdf".
What did you use to create the database?
I are troll
|
|
|
|
|
thanks for the replay, umm i didnt know that this is not a SQL Server... i open new Console APP (to check this, acualy i am building a program to my website in WIN but now i need to learn it first.. i done it before with MYSQL but...)
so~, i clicked on Add new item (in the sulution explorer) and them local database connection.
umm... and them i saw the database in the database explorer and i could edit tables, add tables etc...
if its not mysql, can you explin me where i can find the way to connect to that type of sql server?
Gindi Bar Yahav - Web & Software defeloper.
|
|
|
|
|
Do you want:
* SQL Server (Serves lots of people at once)
* SQL CE (Embedded database)
* MySQL (...) ?
The SQLConnection is used for SQL Server, not MySQL. SQL Server might be installed by the VS2008 setup, MySQL is a separate download.
Downloads be here[^], tutorials on SQL Server are here[^].
I are troll
|
|
|
|
|
thanks you very moch for your help, what i am looking for is a software database so i dont really i need very big database, but ill try to work with SQL server to learn it... the last qustion if you can help me is if you know where i can find database hosting
Gindi Bar Yahav - Web & Software defeloper.
|
|
|
|
|
Gindi Bar Yahav wrote: where i can find database hosting
I'd like to recommend ASP Spider[^]. It's the ideal place to try out new ASP.NET/SQL projects, since it is free.
I are troll
|
|
|
|
|
Hi, add another \ to every \ you have in the connectionstring.
Hope this one can help
Thanks
|
|
|
|
|
i have tried it before, it dosent do any change, becuse i added @ before the connection string.
Gindi Bar Yahav - Web & Software defeloper.
|
|
|
|
|
Hi
Say I have 3 classes Book, Page and Chapter. A Book has many Pages, a Page has many chapters.
I wrote it so that Page has a reference back to Book and Chapter has a reference back to Page which I found really useful because I could pass around Page but still get access to the Book object and find out how many other pages there are (as an example).
Of course, this creates a circular dependency which, now that I need to, I can't serialise this with XML.
What should I have done ? Have another object that maintained references to all these objects ? Passed both Book, Page & Chapter around rather than just Chapter ?
If anyone can shed a little light I would be very pleased.
Thanks
|
|
|
|
|
For serialization, you could decorate the back references properties or public members with the [XmlIgnore] attribute, but that would not solve the deserialization problem.
I suggest you review your design. Could you post the code for your classes, I may be able to give you some pointers.
|
|
|
|
|
Hi, Thanks for replying.
I tried the XmlIgnore route but then realised that there is no AfterSerialisation on XML Serialisation which mean that it wasn't what I wanted.
With classes like this
<br />
public class Book<br />
{<br />
public List<page> Pages { get; set; }<br />
public string Title { get; set; }<br />
}<br />
public class Page<br />
{<br />
public Book ParentBook {get;set}<br />
public List<chapter> Chapters { get; set; }<br />
public int PageNo { get; set; }<br />
public Page(Book parent)<br />
{<br />
ParentBook = parent;<br />
}<br />
}<br />
public class Chapter<br />
{<br />
public Page ParentPage { get; set; }<br />
public string Heading { get; set; }<br />
public string Content { get; set; }<br />
public Chapter (Page parent)<br />
{<br />
ParentPage = parent;<br />
}<br />
}<br />
</chapter></page>
I can do something like this
<br />
Book b = new Book() { Title = "My Book" };<br />
Page p = new Page(b) { PageNo = 1 };<br />
Chapter c = new Chapter(p) { Heading = "Introduction" };<br />
<br />
RenderChapterNavigation(c);<br />
<br />
private static void RenderChapterNavigation(Chapter c)<br />
{<br />
if (c.ParentPage.Chapters.Count == 0)<br />
{<br />
RenderNoChaptersLink();<br />
}else{<br />
RenderChapters(c);<br />
}<br />
}<br />
(this is not the exact code, but you can see how I can references the other chapters after having just passed in a Chapter object).
|
|
|
|
|
What kind of XML structure are you expecting?
|
|
|
|
|
Hi
I have no preference on the structure but what I wanted was to to have the backward-links from Page to Section and Page to Book reestablished automatically when I deserialised it.
Thanks for your replies
|
|
|
|
|
I have a number of test that each submit an object to a Queue (that is declared statically in my Unit test Class) The queue automatically processes each item until there is non left and then fires an event allProcessed.
The problem, is that for each unit test all i test is that it was added to the queue correctally, and i need to let the queue finish processing and at the moment it is getting cut off becasue all the tests finish before the queue processed.
Is there any way to make the test run wait until the allProcessed is fired?
Thanks
|
|
|
|
|
Just checked in
public static void MyClassCleanup()
{
if(QueueLength!=0)
{
Thread.Sleep(1000);
}
}
|
|
|
|
|
Hi,
I've developed an application that uses a few font styles that might not be present in all machines... How can I embed these fonts when I deploy my application at the Client's system, assuming that his system does not have those fonts installed... Please suggest...
Thanks in Advance,
ramz_g
|
|
|
|
|
|
Hi Eddy,
Thanks for the reply... But I think you misunderstood my question... Suppose my client's system does not have a font style named "xyz" which I used in my application. I asked how to embed the font in my application and deploy the application on my client's system so that he sees the same font styles that I used while developing the application.
|
|
|
|
|