Jump to content

HaLo2FrEeEk

Members
  • Posts

    724
  • Joined

  • Last visited

    Never

Everything posted by HaLo2FrEeEk

  1. Would that be something like datagridview1.dispose()? I've never used dispose before, so I'm not sure how to do it or what to search for.
  2. this.Closed += System.eventhandler(this.Form_Closed); Yah, I tried that one, same problem. And by clear I meant that I did DataGridView1.Rows.Clear();, should I try dispose? What would I dispose of? The Datagridview? I'll try it and see what I get.
  3. Hey, I'm having some issues handling a form closing event in C#. I've added this to my designer.cs file: this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing); And this is my Form_Closing() method: public void Form_Closing(object sender, CancelEventArgs cArgs) { if (Directory.Exists("./thumbs")) { Directory.Delete("./thumbs", true); } } The problem is, I'm using files inside the ./thumbs/ directory within the program, so when I try to delete that folder on form close, it gives me an error that a file within the folder is within use. I've tried also using this.Closed and it doesn't do anything either, same issue. The files within the folder are images used in a DataGridViewImageCell. I've tried clearing the datagridview before I delete and that doesn't work either, all the files in there are locked to the process. Is there any way I can delete these files when the program closes? There has to be SOME way.
  4. Ok, thanks corbin and nightslyr, I'll look into both of those methods. One more thing though, this stupid project keeps throwing problem after problem at me! I'm trying to run one method on it's own thread. I've got threading turned on "using System.Threading;" and I'm using this code: private void blf_converter(object fileName) { string filename = fileName.ToString(); // [...] textBox1.Text += "Opening File " + filename + "..." + Environment.NewLine; // This is my problem! // [...] } } private void batchToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Please select the folder where your .blf images are located:"; fbd.ShowNewFolderButton = false; if (fbd.ShowDialog() == DialogResult.OK) { DirectoryInfo batch = new DirectoryInfo(fbd.SelectedPath); FileInfo[] files = batch.GetFiles("*.blf"); progressBar1.Maximum = files.Length; textBox1.Clear(); foreach (FileInfo file in files) { //Thread t = new Thread(blf_converter); //t.Start(file.FullName); //ThreadPool.QueueUserWorkItem(blf_converter, file.FullName); progressBar1.PerformStep(); } } } I get an error in blf_converter that reads this: InvalidOperationException was unhandled Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on. I'm trying to write something to textBox1 but it won't let me because it was created on a different thread than the one running blf_converter(). Is there anything I can do to make this work? I'd like for the new line to be written to the textbox for every file that's processed, as it's processed, not as one big block of text after the processing. Sorry I'm heaping so much on you guys, but google isn't coming up with anything here.
  5. I'm making a simple mailer program that uses SmtpClient() and I've got my form set up with a to, from, subject, and body field, along with a button to send it. I've set up a few if...then statements at the beginning to catch whether the person has put in information for all the required fields (to and from) and confirms if they want to send the message without a subject or body. Well that works just fine, I get a messagebox if I don't enter one of those values...but the code keeps processing. How can I kill it and return the user back to the form if they don't put anything in the to or from field? Right now a user could enter in a to email, from email, no subject, and a body; the script would prompt if they wanted to send the message without a subject. I could hit no, but it'd still send. How can I make it so that the code stops in it's tracks when all required information isn't put in, or if the user says no when asked if they want to send without a subject or body?
  6. Please, someone? I can't get anything further done until I get some help on these subjects.
  7. I'm working on a few different projects right now and I have a few questions about how to do some things. First, I'm making a program that will have some user input: an Xbox Live gamertag and a save location. I want to save this information to an ini file in the same directory as the program executable, but I need to know the best way to read and write an ini config file. A google search returns some results but they all seem kinda complicated, is there just a REALLY simple way to open and access the values from an ini file? I'm pretty sure I'll only need to set those 2 values. Second, what is the best way to parse an XML file retrieved from the internet? I used an httprequest and a streamreader to get the file and return it into a multi-line textbox so I can confirm that it got the file, but I was reading a C# book and saw that there was a method, XmlReader(), that can accept a URL as the parameter, should I do it that way? I need at least 2 pieces of information from each <item> in the file, but most likely I'll want to pull 4 pieces of information: the title, pubdate, and 2 URL's. I was reading, in the same book, about XmlNodeType, so I could do something like this: string url = "[the url to retrieve]"; XmlReader reader = new XmlReader(url); while(reader.Read()) { if(reader.XmlNodeType [...]) //something { [...] //blah blah blah } } And to get the name and value I'd use reader.Name and reader.Value, right? But I also read about ReadElementString(), so to be honest I don't know which to use, which is going to get what I want in the best, fastest, most efficient way. In total there should be 30 <item>'s per XML file, so at 4 pieces of info per <item> and 30 <item>'s, I'll be getting 120 pieces of information. It needs to be fast. And finally, I'll need to download the information found at one of those URL's I'm pulling from the XML file and save it to a temporary directory. It's a thumbnail image that I want to use a reference to the full-size image the person will be downloading (using the program.) For this would I simply create a method that accepts a URL as the parameter and downloads the data and saves it to a temp directory? The images are always jpg, and I want the temp images deleted when the program closes. So I know that I'm asking a lot from you guys, but any help with any of these subjects will be most appreciated! Thanks in advance, ya'll are the best!
  8. Nevermind, sorry. I figured it out. Turns out having it as a bytereader wasn't the best method, I could simply create a streamreader(response.getresponsestream()) then readtoend() that streamreader. It works fine.
  9. I'm downloading an XML file from a remote server using httpwebrequest. Here is my code: using System; using System.IO; using System.Net; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void getXML_Click(object sender, EventArgs e) { byte[] buf = new byte[8192]; if (gamertagBox.Text != "") { string gamertag = gamertagBox.Text; HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.bungie.net/stats/halo3/PlayerScreenshotsRss.ashx?gamertag=" + gamertag); HttpWebResponse response = (HttpWebResponse)req.GetResponse(); Stream responseStream = response.GetResponseStream(); if (response.Headers["Content-Type"] == "text/html") { MessageBox.Show("This gamertag is not valid."); } else { string respString = ""; int count = 0; do { count = responseStream.Read(buf, 0, buf.Length); if (count != 0) { respString += Encoding.ASCII.GetString(buf, 0, count); } } while (count > 0); XMLResult.Text = respString; } } else { MessageBox.Show("You must enter a gamertag"); } } } } This code retrieves an xml file specific to the gamertag entered, then prints the result to a multiline textbox. Well here is the first little bit of the returned data: ???<?xml version="1.0" encoding="utf-8" standalone="yes"?> <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <atom:icon>http://www.bungie.net/images/Bungie-Logo-PicLens-white.png</atom:icon> <title>Recent Halo 3 Screenshots from HaLo2FrEeEk</title> <link>http://www.bungie.net/Stats/Halo3/Screenshots.aspx?player=HaLo2FrEeEk</link> <description>Most recent Halo 3 screenshots taken by a particular gamertag.</description> <language>en-us</language> <pubDate>Thu, 19 Nov 2009 02:46:32 GMT</pubDate> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>BlamDotNet RSS Generator</generator> <webMaster>webmaster@bungie.net (Bungie WebMaster)</webMaster> See the ??? at the beginning? I don't know how that's getting there. It's always there, even if I don't do the do while loop. It's not a huge issue, but I'd really like that to not be there, anyone have any ideas why it might be there and what I can do so that it doesn't get put there. And also if there's a better way to do what I'm doing, I just want to parse the xml for it's values.
  10. Figures, I was supposed to add a reference to system.management.dll in the project references. The link you gave me didn't say that. Needless to say I've figured it out.
  11. That's odd, it says that I need to add "using System.Management;" to the beginning (which I did) then create a ManagementObjectSearcher. Well, I get an error: The type or namespace name 'ManagementObjectSearcher' could not be found (are you missing a using directive or an assembly reference?) Why would this work in the actual compiled program and not when I'm trying to modify it for my own use...
  12. Is it possible to get hardware information like Motherboard manufacturer, model, CPU model and speed, RAM installed, model, etc. I'm looking to make a program for users of my site so all they'll have to do is run the program, then login through the program using their credentials from the website itself and all the hardware specs of their computer will be saved to the database, so people can compare computers...just as a fun "can I do it" project. So anyone know a way to get access to this sort of information?
  13. Ah, I figured it out. I control most of the properties of my databases and accessing user accounts through the control panel at my webhost, I just had to set my username as able to access any database from % hosts (so any host, instead of just %.dreamhost.com, which is the webhost). That made it work. Now I just have to figure out how to reuse query veriables so I can do multiple queries over and over. Right now I have a textarea, a textbox, and a button. You click the menu bar and click connect then you can type a query in the textbox and click the execute button and it'll show the result in the textarea, but when you try to type in a new query and click the Execute button again it throws an error, know any way around that?
  14. Why can I connect to my database via shell if remote access is disabled? I don't understand what exactly I have to do? Adding privelages? This is the command I use to connect to mysql via shell: shell> mysql -h [hostname] -u [username] -p[password] database Should be the same concept right? I'm remotely connecting to the database, is it different because I'm connecting through shell? What privelages would I have to add to be able to access the database from my computer, and would it affect the way I access my database with php on my site?
  15. Ok, I have the MySQL Connector installed and referenced in my project. I have "using MySql.Data.MySqlClient;" at the top, I am using this code to connect: private void btnConnect_Click(object sender, EventArgs e) { string strConnection = "Server=[removed];Database=[removed];Uid=[removed];Pwd=[removed];"; MySqlConnection conSQL = new MySqlConnection(strConnection); conSQL.Open(); } (I've removed the values for server, database, user, and password). This should connect to the database when I click the button...well, it doesn't. It returns an error: Access denied for user '[username'@'99-68-44-40.lightspeed.hstntx.sbcglobal.net' (using password: YES) now "'99-68-44-40.lightspeed.hstntx.sbcglobal.net'" is the first hop I get when I run a tracert, so that's my service provider. Why can't I get past my service provider (AT&T) when trying to connect to a MySQL server on the internet through C#? Please help, I can't complete this project (or even go forward) without being able to do this!
  16. Exactly, or if you want to allow the person to access only, say, html files in the same directory, you can read the directory for files, then use a foreach loop to add all pages with an html extension to an array, and there's your dynamically generated allow array.
  17. Nevermind, I figured it out: <?php $asin = $_REQUEST['asin']; $baseurl = "http://z2-ec2.images-amazon.com/R/1/a=".$asin."+d=_SCR(3,0,0)_+o=01+s=RMTILE+va=MAIN+e=.jpg"; $mainheaders = get_headers($baseurl); if($mainheaders[0] != "HTTP/1.1 200 OK") { die("File does not exist"); } $col = 0; $row = 0; $url = "http://z2-ec2.images-amazon.com/R/1/a=".$asin."+d=_SCR(3,%d,%d)_+o=01+s=RMTILE+va=MAIN+e=.jpg"; while($colheaders[0] != "HTTP/1.1 404 Not Found") { $col++; $colheaders = get_headers(sprintf($url, $col, $row)); } $col--; while($rowheaders[0] != "HTTP/1.1 404 Not Found") { $row++; $rowheaders = get_headers(sprintf($url, $col, $row)); } $row--; echo "Max Colums: ".$col."<br>Max Rows: ".$row; ?> Simple, and it works.
  18. You should note, however, that having an open include like that is EXTREMELY unsafe. Let's say you want someone to put in: blah.php?page=about.html And you have a file called config.php in the same directory, a person could put in: blah.php?page=config.php And get all the information from that page. Make sure you sanitize your inputs.
  19. I have a url that points to a picture. There is a value in the url that can be changed to show a different picture, but there is a limit to how high the value can go. Here is an example: http://z2-ec2.images-amazon.com/R/1/a=0756655498+d=_SCR(3,0,0)_+o=01+s=RMTILE+va=MAIN+e=.jpg d=_SCR(3,0,0)_ The format for that is: (zoom level, column, row) It's the url for the zoom images on Amazon. This particular image has 5 colums and 6 rows. I would like to be able to download the full-size images and construct them into one image, instead of having 30 individual smaller images. What I want to do is recursively check the url, increasing the colum value until the image no longer returns a "HTTP/1.1 200 OK" code, then do the same with the rows. For this image it's kinda pointless since I know how many rows and cols it has, but for other images I won't know without manually checking. Here's what I have so far: <?php $asin = $_REQUEST['asin']; $col = 0; $row = 0; $url = "http://z2-ec2.images-amazon.com/R/1/a=".$asin."+d=_SCR(3,".$col.",".$row.")_+o=01+s=RMTILE+va=MAIN+e=.jpg"; $mainheaders = get_headers($url); if($mainheaders[0] != "HTTP/1.1 200 OK") { die("The image does not exist"); } $col++; $row++; do { $rowheaders = get_headers($url); $row++; } while($rowheaders[0] == "HTTP/1.1 200 OK"); ?> When I run this it gives me a 500 Server Error, don't know why. So I tried changing it to this: <?php $asin = $_REQUEST['asin']; $col = 0; $row = 0; $url = "http://z2-ec2.images-amazon.com/R/1/a=".$asin."+d=_SCR(3,".$col.",".$row.")_+o=01+s=RMTILE+va=MAIN+e=.jpg"; $mainheaders = get_headers($url); if($mainheaders[0] != "HTTP/1.1 200 OK") { die("The image does not exist"); } $col++; $rowheaders = get_headers($url); echo $url."<br><br>"; print_r($rowheaders); ?> increase the $col variable by 1 then get the headers again and print the new url and the headers again...this is my result: http://z2-ec2.images-amazon.com/R/1/a=0756655498+d=_SCR(3,0,0)_+o=01+s=RMTILE+va=MAIN+e=.jpg Array ( [0] => HTTP/1.1 200 OK [1] => Date: Wed, 04 Nov 2009 01:15:37 GMT [2] => Last-Modified: Wed, 02 Sep 2009 18:38:22 GMT [3] => Server: Server [4] => Content-Type: image/jpeg [5] => X-Cache: MISS from cdn-images.amazon.com [6] => X-Cache: MISS from cdn-images.amazon.com [7] => Content-Length: 15902 [8] => Connection: close ) Why did it not increase the $col variable in the url? The new url should be: http://z2-ec2.images-amazon.com/R/1/a=0756655498+d=_SCR(3,1,0)_+o=01+s=RMTILE+va=MAIN+e=.jpg How can I achieve what I want, to recursively check the url until I reach the maximum col and row values? The way I check if I'm at max is, since there are 5 columns in this image, if col was set to 6 then get_headers[1] would return "HTTP/1.1 404 Not Found", so I can use that to confirm the existence of the url. Is there some loop I can do? I don't need it to print anything until it gets to the maximum values of $col and $row.
  20. http://www.bungie.net/online/default.aspx That's the page I got all that code from. I didn't see an onsubmit event.
  21. You'll still need to write your own function, yes, but the way I do it has always been simpler (in my opinion). Keep in mind this is just the function to get the new size, not to actually save the image: <?php $maxWidth = 155; // The maximum width of the image, this should be outside the function function imageSize($image) { // $image needs to be a valid image resource GLOBAL $maxWidth; // This makes it so you can use the $maxWidth variable $width = imagesx($image); // Gets the width of $image $height = imagesy($image); // Gets the height of $image if($origWidth > $maxWidth) { $diff = $maxWidth / $origWidth; // Gets the ratio of the max width to the actual width $width = $maxWidth; // Updates $width with the value of $maxWidth $height = $diff * $origHeight; // updates $height using the proper ratio } $imgSize[] = $width; $imgSize[] = $height; } $img = imagecreatefromjpeg("archer.jpg"); $imgSize = imageSize($img); echo "<img src=\"archer.jpg\" width=\"".$imgSize[0]."\" height=\"".$imgSize[1]."\" alt=\"\">"; ?> If you want to control both height and width it'll take a little modification, but not much. If you plan on loading more than just jpgs you'll also need to do a little modification to the "imagecreatefromjpeg()" line. What this does it read in an image, checks if the image's width is larger than the maximum acceptable width, $maxWidth. If it is it resizes the width to the max width, then calculates the height by multiplying the actual height by the result of the $maxWidth and $origWidth, which will always be less than 1 if the actual width is bigger than the max width. Ok, so anyway, let me know if you need mor help.
  22. Well there's only the one form on the page, and I'm thinking that within the __doPostBack function there is an if...then statement that checks if the form has an onsubmit attribute, if it doesn't then it sets the hidden values and submits the form...but it's not actually submitting to a new page, I just want to know how the AJAX is firing.
  23. He just said they're residing in 2 different servers, I'm assuming he's trying to POST data from a php application (that he has control over) to an asp.net application (which he doesn't have control over). I could be wrong though. Why would he use $_GET if he wants to POST? POST =/= GET. I would construct a form with the url of the remote asp.net application as the action, then fill the inputs with the data you want, making sure the id's are right, then submit it using Javascript or something, or manually.
  24. http://php.net/imagecopyresized Look into it, it'll help you save an image resized. And I'm wondering, are you simply trying to resize an image to a max height or width of $maxSize, keeping the aspect ratio? If that's all you're doing there's a much, MUUUCHHH simpler way.
  25. something like this: <?php $dumplink = $_REQUEST['access']; $dumplinkinfo = file_get_contents("$dumplink.html"); // This will return the file into a string $dumplinkinfo = nl2br($dumplinkinfo); // This converts all newline characters with line-breaks (<br>'s) $dumplinkinfo = explode("<br />", $dumplinkinfo); // This will break the string into lines by line-break characters and put it into an array foreach($dumplinkinfo as $dumplinkline) { // Iterate through the array $linkline = explode(" || ", $dumplinkline); // Breaks the string up by " || " characters and puts the results into an array $linkname[] = $linkline[0]; // Assigns the first value to the $linkname array $linkurl[] = $linkline[1]; // Assigns the second value to the $linkurl array } print_r($linkname); // Print the $linkname array print_r($linkurl); // Print the $linkurl array ?> I tested this with this string: link1 || http://link1.com link2 || http://link2.com link3 || http://link3.com link4 || http://link4.com And it returned 2 arrays, $linkname and $linkurl. To parse through these, given that you know the location (line number, starting with 0) of the link you want, do this: $getlink = $_REQUEST['link'] $link_name = $linkname[$getlink']; $link_url = $linkurl[$getlink]; Simple enough. A question for you now, is there a reason you're using a flatfile and not an actual database? I also know a way to make is so you can call up a link by it's name and not by it's number, if you're interested let me know.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.