|
|
Hello Everyone!
I am using Visual C# to make a program, which compiles a code from string to export a new exe.
the first can update some configs for the second, when i try to run the second program i get this Exception:
The specified string is not in the form required for an e-mail address.
While the code is:
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(""smtp.gmail.com"");
mail.From = new MailAddress(Config.username);
mail.To.Add(Config.toEmail);
mail.Subject = Config.subject; ;
mail.Body = text;
if (sendImage)
{
var stream = new MemoryStream();
img.Save(stream, ImageFormat.Jpeg);
stream.Position = 0;
mail.Attachments.Add(new Attachment(stream, ""image / jpg""));
}
SmtpServer.Port = Config.smtpPort;
SmtpServer.Credentials = new System.Net.NetworkCredential(Config.username, Config.password);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Console.WriteLine(""Email has been sent!"");
}
catch (Exception e) { Console.WriteLine(e.Message); }
|
|
|
|
|
That's not valid C#: strings are delimited by a single double quote at each end, not two.
And that code does nothing with EXE files, it's to do with emails ...
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Member 13858110 wrote: <When i try the code alone, it works normally, while when i use to compile the code my self i get the error. It is not a compiler error, but an exception thrown at runtime.
mail.From = new MailAddress(Config.username);
mail.To.Add(Config.toEmail); One of those two isn't a valid email-address.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Tried to use email for both, but still the same error, while when i use Console.WriteLine(email, password); it shows the same as the ones ive written.
|
|
|
|
|
You need to use your debugger to see exactly what value is being used when the program runs.
|
|
|
|
|
Member 13858110 wrote: Tried to use email for both, but still the same error, while when i use Console.WriteLine(email, password); it shows the same as the ones ive written. The FormatException will be thrown when the "to" adress is in the wrong format. It may contain a newline, or something else, but it is not thrown at random. If it contains multiple addresses, separate them with a comma, not a ";".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
fixed it, it was a format changer ive added, but removed it.
|
|
|
|
|
Why on earth are you doing it this way when you could just put the required values in the app.config file and load them from there, skipping the entire process of compiling code?
|
|
|
|
|
Hi everyone, I am a freshman in C# and php. I currently followed this link: ESP8266 Communication With Server and ESP8266[^] and tried to play with ESP8266.
The arduino part worked fine and I could get the message from a file in my website called datastorage.txt, and below is the php file (named as writefile.php) for me to add message into the txt file:
<?php
$val = $_GET["data"];
$fileContent=$val."\n";
$fileStatus=file_put_contents("datastorage.txt",$fileContent,FILE_APPEND);
if($fileStatus != false)
{
echo "SUCCESS. Data written in file.";
}
else
{
echo "FAIL. Could not connect to file.";
}
?>
If I need to add new message, I always need to enter url like: http://abc.com/writefile.php?data=helloworld (the message would be helloworld in this case), which is not convenient at all.
Therefore, I tried to build a winform to contact with the writefile.php as below:
private void SendBtn_Click(object sender, EventArgs e)
{
SendData();
}
private void SendData()
{
string text = TextBox.Text;
string post = "data=" + text;
byte[] data = Encoding.ASCII.GetBytes(post);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://abc.com/writefile.php");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream stream = req.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
}
When I typed a message into the textbox and click "send" button, no error appeared. However, I tried to open datastorage.txt inside my website, and the file only added a blank character " " in the new line but not my text message.
Am I using a wrong method / direction to build the winform?? Thanks very much.
|
|
|
|
|
codeNewer wrote: $val = $_GET["data"]; codeNewer wrote: req.Method = "POST";
You need to understand the difference between GET and POST requests:
HTTP Methods GET vs POST[^]
Your PHP code is reading the variable from the querystring. Your C# code is sending the variable in the request body.
You either need to modify your PHP code to check the $_POST as well as the $_GET ; or modify your C# code to make a GET request.
You also need to modify your C# code to actually send the request.
private void SendData()
{
string text = TextBox.Text;
string url = "http://abc.com/writefile.php?data=" + Uri.EscapeDataString(text);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
using (var response = req.GetResponse())
{
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have just practise to grab some data from a web page.
Of course, I am new in c#.
I am using regex but it does not word. and return null.
using HtmlAgilityPack;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load("https://www.videoblocks.com/video/after-effects-cs5-template-bracket-titles-65zdx8e");
var title = doc.DocumentNode.SelectNodes(xpath: "//ul[@class='stockItemInfo-stockSpec']").FirstOrDefault().InnerText.Split(':').FirstOrDefault();
var secp = doc.DocumentNode.SelectNodes("//ul[@class='stockItemInfo-stockSpec']//li//span").FirstOrDefault().InnerText;
Console.Write(title+":"+secp);
Console.ReadKey();
}
}
}
|
|
|
|
|
You can check the documentation in Html Agility Pack - documentation[HTML Agility Pack]
It is different from regex.
You can hit a breakpoint in "doc" variable and debug, then it will be easier to inspect the elements on how to navigate it.
[Signature space for sale]
|
|
|
|
|
thanks for your reply
Could you tell me how can I add the breakpoint in doc?
|
|
|
|
|
Hi,
i am looking for a way to extract the entire content of a zip file into a folder without using any external dependencies like Interop.Shell32.dll or 3rd-Party Libs like DotNetZip etc. The entire thing should run from within a single assembly. I personally would like to use the Windows build-in ZIP-Shell extension available from windows XP to Win10 by accessing it with preferably late binding via .NET/C#, but i am kinda stuck on how to do it and what the COM-Interfaces/Types for that should look like. Any help would be really higly appreciated.
best
K.
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."
|
|
|
|
|
Zipping using System.IO.Compression[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi Eddy,
thanks for the answer. I forgot one thing to mention here, that the application is using the 2.0 .NET Framework and cant compiled against anything else for compatibility use with other libraries/references included. The System.IO.Compression needs at least 4.5 Framework.
best
K.
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."
|
|
|
|
|
Kerem Guemruekcue wrote: I forgot one thing to mention here, that the application is using the 2.0 .NET Framework and cant compiled against anything else for compatibility use with other libraries/references included. The System.IO.Compression needs at least 4.5 Framework. It doesn't; it is part of 2.0.
See MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
This is true in terms of availability of the namespace, but the unzipping zip file classes are available starting 4.5 FW. See for yourself: ZipFile Class (System.IO.Compression)[^]
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."
|
|
|
|
|
Kerem Guemruekcue wrote: This is true in terms of availability of the namespace, but the unzipping zip file classes are available starting 4.5 FW. See for yourself You are referring to a helper-class that simplifies the tasks. The GZipStream is available in 2.0, and you could zip/unzip in 2.0 without using third-party libraries. Example on MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I am not sure how this will help me to unpack a zip file into a folder. The example there only shows how to compress/decompress a single file with GZip compression. I am familiar with that mechanism and it would be overkill to reinvent a library from Deflate/GZip classes in .NET to create a unpacker for folders packet into a zip container file. The example works just fine on a single file, but not on a Zip archive.
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."
|
|
|
|
|
Kerem Guemruekcue wrote: I am not sure how this will help me to unpack a zip file into a folder. The example there only shows how to compress/decompress a single file with GZip compression. I am familiar with that mechanism and it would be overkill to reinvent a library from Deflate/GZip classes in .NET to create a unpacker for folders packet into a zip container file. Then use one of the existing libraries. Did you not state you did not want a dependency on things like SharpZipLib and DotNetZip?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Quote: Then use one of the existing libraries. Did you not state you did not want a dependency on things like SharpZipLib and DotNetZip?
Yes, i did and thats why i was prefering the late binding option to the shell zip functionality build into windows. As said, the entire thing should be running from a single exe file with no extra libs attached. the zip com extension is available from XP up to 10. using the GZip/Deflate classes in that namespace supporting .NET 2.0 would require to implement a full unzipper for zip containers in zip format like implemented in the helper classes available starting 4.5 FW. that would be a total overkill.
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."
|
|
|
|
|
|
Hi Richard,
thanks for the answer. Yes, i have seen that article before, but this uses early binding with a com wrapper. Thats the easy way, but i am looking for late binding at runtime with no additionall assembly file, like this project uses.
best
K.
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
-----------------------
"This reply is provided as is, without warranty express or implied."
|
|
|
|