today we were trying to transfer files with using C# but there are some problems here i don't really know what is wrong
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FileTransfer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
var userDir = new DirectoryInfo(Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile));
string path = curDir + #"\1.jar";
string path2 = userDir + #"\Desktop\2.jar";
File.Move(path, path2);
}
}
}
It says 1.jar file cannot found.
Try this:
string path = Path.Combine(curDir,"1.jar");
string path2 = Path.Combine(userDir,"Desktop","2.jar");
//if this still doesn't work, put a breakpoint after these two lines
When your breakpoint is hit look at the value of path. Is there a even file at that location? If not, you need build your path correctly.
Also, it would be a good idea to check if the file exists before you try to move it:
if(!File.Exists(path))
{
//handle this scenario here
return;
}
File.Move(path,path2);
Related
So after following some tutorials and using https://openweathermap.org/current, I got some code going and now I've been spending hours trying to figure out why it won't work. I started by making a Windows Forms app and made this interface. At first it was going to be able to find the weather of any city you typed in, but I can't find such an option on openweathermap so I only restricted it to Seoul, Korea. However I don't understand why nothing happens when I click the button, I thought it should bring back the forecast in the text boxes.. If anyone could help it would be really appreciated.
This is my full code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Net;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string city;
city = txtcity.Text;
string uri = string.Format("http://api.openweathermap.org/data/2.5/weather?q=Seoul&mode=xml&appid=78dff84492be32f8b4f77692904607a1", city);
XDocument doc = XDocument.Load(uri);
string iconUri = (string)doc.Descendants("icon").FirstOrDefault();
WebClient client = new WebClient();
string maxtemp = (string)doc.Descendants("temperature.max").FirstOrDefault();
string mintemp = (string)doc.Descendants("temperature.min").FirstOrDefault();
string maxwindm = (string)doc.Descendants("maxwind_mph").FirstOrDefault();
string maxwindk = (string)doc.Descendants("maxwind_kph").FirstOrDefault();
string humidity = (string)doc.Descendants("avghumidity").FirstOrDefault();
string country = (string)doc.Descendants("country").FirstOrDefault();
string cloud = (string)doc.Descendants("text").FirstOrDefault();
txtmaxtemp.Text = maxtemp;
txtmintemp.Text = mintemp;
txtwindm.Text = maxwindm;
txtwindk.Text = maxwindk;
txthumidity.Text = humidity;
label7.Text = cloud;
txtcountry.Text = country;
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
You have burned this info in your link that you are asking for a certain city (Seul):
"http://api.openweathermap.org/data/2.5/weather?q***=Seoul***&mode=xml&appid=78dff84492be32f8b4f77692904607a1"
There is no info in your code that you changed it in this link. Please try this:
String.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&mode=xml&appid=78dff84492be32f8b4f77692904607a1",city);
Hope will fine :)
I want to monitor some directory using FileSystemWatcher but FileSystemWatcher.created is not working at all .
CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Configuration;
using System.Threading;
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
static string fileName;
static string dirFileName;
static void Main(string[] args)
{
string _Dir = ConfigurationManager.AppSettings["Dir"];
Console.WriteLine("MAIDProcessFileTest processing started");
FileSystemWatcher _watch = new FileSystemWatcher();
_watch.Path = _Dir;
_watch.Created += FileCreated;
Console.ReadLine();
}
private static void FileCreated(object sender, FileSystemEventArgs e)
{
Console.WriteLine("Before is treat");
fileName = Path.GetFileName(e.FullPath);
dirFileName = Path.GetDirectoryName(e.FullPath) + #"\" + Path.GetFileName(e.FullPath);
}
}
}
Can anybody tell me that why this code is not working ... whenever I debug _watch.Created += FileCreated; is not working at all. where is the error can anybody tell me . Please Help
You need to start it
_watch.EnableRaisingEvents = true;
FileSystemWatcher.EnableRaisingEvents Property
You should probably start here though
FileSystemWatcher Class
It has a great example, and everything you need to know to use it
I have a problem with my project.
I have a js function sig7 which generates me hash.
But the charset of html page is required to be utf-8.
I try to execute this js in my C# app with library
Everything is OK, but generated hash is not valid. I think it happens because the charset of code isn't utf-8.
My app:
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.IO;
using Noesis.Javascript;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("c://lib.js");
string script = sr.ReadToEnd();
JavascriptContext context = new JavascriptContext();
context.Run(script);
var sig = context.Run(#"sig7('057d194dd856d4f8cd15bc85fbbddbf136df809f72f5a435e6af41c1f82f950f,Id166084073,ldsclldscl');").ToString();
richTextBox1.Text = sig;
}
}
}
sig must be 1dbde1d62b6e0dca7d56f72e50c178132e236978d2dba1e2c3ada5b7b8973aeb but not 7211ed8fe85d750c26cb5abb499bfa88b7cecbe968fc6cc7efa69dc496c8ae12 which is generated by my app.
Any help?
Should this line:
var sig = context.Run(#"sig7('057d194dd856d4f8cd15bc85fbbddbf136df809f72f5a435e6af41c1f82f950f,Id166084073,ldsclldscl');").ToString();
Be:
var sig = context.Run(#"sig7('057d194dd856d4f8cd15bc85fbbddbf136df809f72f5a435e6af41c1f82f950f', 'Id166084073', 'ldsclldscl');").ToString()
?
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.IO;
using System.Security.AccessControl;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string Directoryd = "D:";
string mydirectory = Directoryd + "\\" + "rs\\";
if (!Directory.Exists(mydirectory))
{
Directory.CreateDirectory(mydirectory);
}
DirectoryInfo di = new DirectoryInfo(mydirectory);
DirectorySecurity ds = di.GetAccessControl();
ds.AddAccessRule(new FileSystemAccessRule(#"*",FileSystemRights.FullControl,AccessControlType.Allow));
di.SetAccessControl(ds);
}
}
}
this is my code when i execute this the pop up is showing that
Actually, this code is to create a folder rs and set its permission to deny full control but on running the error come with the message
Some or all identity references could not be translated.
What is the error?
You should change the following line:
ds.AddAccessRule(new FileSystemAccessRule(#"*",FileSystemRights.FullControl,AccessControlType.Allow));
to:
ds.AddAccessRule(new FileSystemAccessRule(#"Everyone",FileSystemRights.FullControl,AccessControlType.Allow));
Also if you look at the following Everyone Group there is an answer a bit further down that suggests you should use SSID's instead of the names.
Try the group "Everyone", not *.
I made a launcher for my game server. (World of Warcraft)
I want to get the installpath of the game, browsed by the user.
I'm using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.
using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string InstallPath, WoWExe, PatchPath;
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey LocalMachineKey_Existence;
MessageBox.Show("Browse your install location.", "Select Wow.exe");
OpenFileDialog BrowseInstallPath = new OpenFileDialog();
BrowseInstallPath.Filter = "wow.exe|*.exe";
if (BrowseInstallPath.ShowDialog() == DialogResult.OK)
{
InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName);
WoWExe = InstallPath + "\\wow.exe";
PatchPath = InstallPath + "\\Data\\";
LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(#"SOFTWARE\ExistenceWoW");
LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath);
LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath);
LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe);
}
}
}
}
The problem is:
On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this:
C:\ASDData , so it forgots a backslash :S
Look at this picture:
http://img21.imageshack.us/img21/2829/regedita.jpg
My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S
I have windows 7, with .NEt 3.5
Please help me.
Can you debug and see what InstallPath contains?
Try it with Path.Combine instead of string concatenation, e.g.:
WowExe = Path.Combine(InstallPath, "wow.exe");
PatchPath = Path.Combine(InstallPath, #"\Data\");