I have created a WCF service which sends an sms by using the supplied values. This then return XML in a string variable. I have managed to get the string loaded into an XmlDocument but then when I try and load it onto a Webform control I get an error because the XmlDocument is in memory and does not have a physical path. How can I get this loaded into my webform control(WB_XMLOut). Please see my code below what I have tried.
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 LeadProcessTest.LeadProcessor;
using System.Xml;
namespace LeadProcessTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BT_Process_Click(object sender, EventArgs e)
{
LeadProcessorClient LP = new LeadProcessorClient();
string UName = Convert.ToBase64String(Encoding.UTF8.GetBytes(TB_UName.Text));
string PWord = Convert.ToBase64String(Encoding.UTF8.GetBytes(TB_Pass.Text));
string XMLIn = Convert.ToBase64String(Encoding.UTF8.GetBytes(TB_XMLin.Text));
LP.Open();
string Result = LP.Lead_Processing(UName, PWord, XMLIn);
LP.Close();
XmlDocument XML = new XmlDocument();
XML.LoadXml(Result);
WB_XMLOut.Url = new Uri(XML);
}
}
}
Related
Hello it is probably easy question for you, I'm a beginner and I'm making my own simple game and I want to use a Class:Gamer, which I want to initialize in MainWindow(Form1.cs) from a save file. From then, I want to use it on another Forms aswell, but somehow I can't make the instance go public.
Could you tell me what I'm doing wrong? Or is there another way how to solve this?
Thank you :)
Code on Form1:
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.Drawing.Text;
using System.IO;
namespace THE_GAME
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Gamer Player;
private void MainWindow_Load(object sender, EventArgs e)
{
//load from savefile lvl;hp;money;gun;armor,name
string allData = File.ReadAllText("../../saveFile/save.txt");
string[] dataFromSave = new string[5];
dataFromSave = allData.Split(';');
Player = new Gamer(dataFromSave[0], dataFromSave[1], dataFromSave[2], dataFromSave[3], dataFromSave[4], dataFromSave[5]);
}
}
}
Code on secondForm2:
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.Drawing.Text;
namespace THE_GAME
{
public partial class Statistics : Form1
{
public Statistics()
{
InitializeComponent();
}
private void Statistics_Load(object sender, EventArgs e)
{
//labels stats
labelName.Text = Form1.Player.GetName();
labelHealth.Text = Form1.Player.GetHealth().ToString();
labelMoney.Text = Form1.Player.GetMoney().ToString();
}
private void buttonBack_Click(object sender, EventArgs e)
{
MainMenu menu = new MainMenu();
menu.Show();
this.Close();
}
}
}
Thank you for your time.
To get at the Gamers Player object from a different Form just do
Form1.Player;
ie
var nam = Form1.Player.Name;
Form1.Player.Die();
etc
PS As I said in a comment - its extremely odd to dereive a form of yours from another one of your forms. Like this
public partial class Statistics : Form1
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.Net;
namespace Garfield
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
download("https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/2019/2019-11-25.gif?v=1.1", "e.gif");
}
public void download(string link, string name)
{
using (WebClient Client = new WebClient())
{
Client.DownloadFile(link, name);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
Using the code above I downloaded an image online, now how do I set the location of that file to somewhere else instead of it being in the debug folder?
This can be done through mentioning a valid desired location and name when download.
Client.DownloadFile("https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/2019/2019-11-25.gif?v=1.1",
#"C:\yourfolder\yourfilename.png");
You can pass an entire path to your download method:
download("https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/2019/2019-11-25.gif?v=1.1", "C:\\Users\\(You)\\Documents\\e.gif");
Just replace everything before "e.gif" with the path you desire.
See more here: https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=netframework-4.8
I have this code. When I need to print my report, it shows me a Print Dialog. I want to select my print name by code, and print my report without showing PrintDialog.
This is my 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.Drawing.Printing;
namespace POS.Reports
{
public partial class ProductsReceiptPreview : Form
{
BindingSource _data;
string _total, _cashr, _cashc;
public ProductsReceiptPreview(BindingSource data, string total,
string cashr, string cashc)
{
InitializeComponent();
_total = total; _cashr = cashr; _cashc = cashc;
_data = data;
}
private void ProductsReceipt_Load(object sender, EventArgs e)
{
DataReceiptBindingSource.DataSource = _data;
Microsoft.Reporting.WinForms.ReportParameter[] param = new
Microsoft.Reporting.WinForms.ReportParameter[]
{
new Microsoft.Reporting.WinForms.ReportParameter("ptotal",
_total),
new Microsoft.Reporting.WinForms.ReportParameter("pcashr",
_cashr),
new Microsoft.Reporting.WinForms.ReportParameter("pcashc",
_cashc),
new Microsoft.Reporting.WinForms.ReportParameter
("pdate",DateTime.Now.ToString())
};
this.rptProductsReceipt.LocalReport.SetParameters(param);
this.rptProductsReceipt.RefreshReport();
this.rptProductsReceipt.ZoomMode =
Microsoft.Reporting.WinForms.ZoomMode.PageWidth;
}
private void btnReports_Click(object sender, EventArgs e)
{
rptProductsReceipt.PrintDialog();
}
}
}
i never use your method but i use this
rptProductsReceipt.PrintToPrinter(1, false, 0, 0);
after using adapter and data table
I try to make a simple weather aplication but i get an exception.
I have location activated. I try to run in emulator for phone, not working
the exception
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace TryToMakeWeatherApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var pos = await LocationManage.GetLocation(); //Here i'm geting the error
var lat = pos.Coordinate.Latitude;
var lon = pos.Coordinate.Longitude;
var weather = WeatherMap.GetWeather(lat, lon).ToString();
WeatherTxt.Text = weather;
}
}
}
This is code from MainPage.
And this is the LocationManage class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;
namespace TryToMakeWeatherApp
{
class LocationManage
{
public async static Task<Geoposition> GetLocation()
{
var accessStatus = await Geolocator.RequestAccessAsync();
var geolocator = new Geolocator { DesiredAccuracyInMeters = 0 };
var position = await geolocator.GetGeopositionAsync();
return position;
}
}
}
in your package.manifest file have to turn on this capability too
i'm struggling with simplest request handling in C# .NET, whenever i try to read something from request i usually get an Empty value.
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class server_save : System.Web.UI.Page
{
private string TXT_PATH = HttpContext.Current.Server.MapPath("files/saved.txt");
protected void Page_Load(object sender, EventArgs e)
{
Response.AppendHeader("Access-Control-Allow-Origin", "*");
string DATA = Request["data"];
try
{
StreamWriter writer = new StreamWriter(TXT_PATH, true, Encoding.Default);
writer.WriteLine(DATA);
writer.Close();
Response.Write(DATA);
}
catch (Exception)
{
Response.Write(TXT_PATH);
}
}
}
http://pastebin.com/nJYBm4mX