Can someone tell me how i can change the .xml file that a flash movie loads using c#. ie: i would like an ActionScript variable that defines the location of the flash movie. I would like to be able to change this variable using c# if possible.
i dont really know how it would look, but something like:
<object xmlpath='" + myCSharpVar + "'" ...></object>
I just starting this, but my ultimate goal is to create a .swf movie that can load an xml file that specifies images, etc. However i want to use the same .swf file in multiple places and only have to change a ref to what xml file it uses - and my Flash/ActionScript skills are very rusty.
To clear it up a bit, in AS you can do something like:
loader.load( new URLRequest("IWantThisNameDynamic.xml") );
how can i define that xml file in my c# code?
I'm quite sure you cannot "create" your own attributes for the object tag. At least not without consulting with the w3c ;-)
Passing values to flash is done via the "flashvar"-param:
<object ...>
<param name="flashvars" value="&xmlpath=<path to xml>"/>
</object>
In the flash-movie you can now access the path to your xml via the "xmlpath"-variable.
Edit: sorry, question was about ASP.NET
If you were using an AxShockwaveFlash object in C#, you would set the variables this way:
AxShockwaveFlash movie; // already exists
string xmlPath = "some path";
movie.FlashVars = "xmlPath=" + xmlPath; // url-encoded variables
Then in AS2:
var xmlPath:String = _level0.xmlPath;
Or in AS3:
var xmlPath:String = loaderInfo.parameters.xmlPath;
Related
I am working on a WPF application and I have a simple XML file that I am parsing using 'XmlDocument' and is working fine for the readinh part.
I want the use to be able to add, edit or delete any node and save these changes to the file.
I tried using 'XElement' but it seems to change the instance itself and not the file.
My XML file looks something like this:
<Configuration>
<A_0.04_5>
<ML407Configuration>
<AM_Amp>10</AM_Amp>
<AMRJ_Amp>10</AMRJ_Amp>
<FM_Freq>20</FM_Freq>
<FM_Phase_Shift>20</FM_Phase_Shift>
</ML407Configuration>
<BertConfiguration>
<BERT_LR>25.78125</BERT_LR>
<BERT_PRBS>7</BERT_PRBS>
<BERT_Scaling>1000</BERT_Scaling>
</BertConfiguration>
</A_0.04_5>
<B_1.333_0.15>
<ML407Configuration>
<AM_Amp>10</AM_Amp>
<AMRJ_Amp>10</AMRJ_Amp>
<FM_Freq>20</FM_Freq>
<FM_Phase_Shift>20</FM_Phase_Shift>
</ML407Configuration>
<BertConfiguration>
<BERT_LR>25.78125</BERT_LR>
<BERT_PRBS>7</BERT_PRBS>
</BertConfiguration>
</B_1.333_0.15>
<C_4_0.05>
<ML407Configuration>
<BUJ_LR>25</BUJ_LR>
<BUJ_Pattern>7</BUJ_Pattern>
<PM_BUJ_Amp>7</PM_BUJ_Amp>
<BUJ_Amp>80</BUJ_Amp>
</ML407Configuration>
<BertConfiguration>
<BERT_LR>25.78125</BERT_LR>
<BERT_PRBS>7</BERT_PRBS>
</BertConfiguration>
</C_4_0.05>
</Configuration>
What I tried is the following:
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+"/Configuration.xml";
XElement xml = XElement.Load(filePath);
// This seems to remove the node from xml instance and not from the file
// Should I save the file again or is there another way to do it
// Same applies for add and edit
xml.Elements("C_4_0.05").Remove();
I have seen a lot of similar questions but I don't know if any of them change directly to the file or not
XElement.Load loads an XML structure from a file into memory. Any changes you make to that structure are also done in memory. If you want to write those changes back to a file (technically called serialization) you need to call XElement.Save.
I have an issue with a class library; I am preparing a library with an interface that represents a specific data storage signature. The purpose is to use the interface as a basis for implementing a number of specific classes storing configuration information in different formats (text files, xml files, etc.) while retaining the same usage profile to the application using it. I have a problem, though. In this case I am trying to embed an xml file as a resource - this file is one type of format to store configuration data. The file is located as an embedded resource in a subfolder to the project, as shown in the attached illustration.
In the following code snippet it is shown how I have implemented the functionality until now.
public ConfigInfoXmlSource()
{
if (!string.IsNullOrEmpty(Settings.Default.CurrentConfigFile))
FileNameAndPath = Settings.Default.CurrentConfigFile;
else
FileNameAndPath = DefaultConfigFileName + DefaultFileExtension;
// Prepare XML.
System.Reflection.Assembly a = Assembly.GetExecutingAssembly();
XmlDocument doc = new XmlDocument();
Stream manifestResourceStream =
a.GetManifestResourceStream("TestTool.Config.Config1.xml");
if (manifestResourceStream == null)
{
// ???
}
...
doc.Load(manifestResourceStream);
...
}
In the section marked "Prepare XML" I am trying to read a stream from the embedded resource. After the reading, it is tested whether a stream was indeed created. If the file is found, the manifestResourceStream will contain the xml data - so far so good. The problem arises if the file for some reason has been accidentally deleted - in that case I want to create a new file as an embedded resource to replace the deleted file. That is supposed to happen in the conditional in the part shown as "???".
I have tried everything I could think of, searched Google for answers, etc. - to no avail.
Does anyone have a clue to how this is accomplished? Any help will be greatly appreciated.
Thanks in advance.
Best regards.
If you have a embedded resource,it is built into your binaries.It is not an physical file,rather something which is present inside the built file(dll in this case).So,once it is included,I do not think it can ever be deleted. As per my knowledge embedded resource can only be set while building your project binaries and you can not explicitly do it at runtime as it is not needed due to reasons mentioned above.
Basiclly I'm trying to create an HTML, I already have it written but I want the user to be able to put some text on the textboxes and saving it into strings and use later when creating the HTML file.
I tried playing abit with StreamWriter but I don't think that will be the best idea.
Also I want it to open on the default web browser , or just on IE if it's easier after the file is created.
I really need help as I'm struggling especially with the creating part.
Thanks for reading!
You can also do this without external libraries.
Set up your HTML file as follows:
<!DOCTYPE html>
<html>
<header>
<title>{MY_TITLE}</title>
</header>
<body></body>
</html>
Then edit and save the HTML from C#:
const string fileName = "Foobar.html";
//Read HTML from file
var content = File.ReadAllText(fileName);
//Replace all values in the HTML
content = content.Replace("{MY_TITLE}", titleTextBox.Text);
//Write new HTML string to file
File.WriteAllText(fileName, content);
//Show it in the default application for handling .html files
Process.Start(fileName);
If you already have the HTML you want to export (just not customized), you could manually add format strings to it (like {0}, {1}, {2}) where you want to substitute text from your app, then embed it as a resource, load it in at runtime, substitute the TextBox text using string.Format, and finally write it out again. This is admittedly a really fragile way to do it, as you need to make sure the number of parameters agrees between the resource file and your call to string.Format. In fact, this is a horrible way to do it. Actually, you should do it the way #EmilePels suggests, which is basically a less fragile version of this answer.
I've been working on a project (C#) and part of it was filling a data grid with an embedded xml file.
Although I've now found a way to make this work, i am still confused as to to theory behind it. And I'd like to stop and make sure i fully understand it before i continue with this project.
The code that i have working currently is;
XmlDataDocument myXML = new XmlDataDocument();
StringReader mytempXML = (new StringReader(BasicTest.Properties.Resources.myxml));
myXML.DataSet.ReadXml(mytempXML);
What is confusing to me is that before this solution, I was trying the below;
myXML.DataSet.ReadXml(BasicTest.Properties.Resources.myxml);
and it wasn't working. However using the full file path (like below) was working.
myXML.DataSet.ReadXml("C:/..etc../myxml.xml");
The Question I have is: why is a StringReader required for the ReadXml method if you're reading from a resource, but using a full file path works without?
If anyone could provide an explanation, that would be great.
Thanks.
This is because the ReadXml method takes a string. That string must be the name of a file. It cannot be XML. If you pass it a string that is XML, it will think that is the name of the file! It doesn't have the smarts to look at the string and ask "Is this string XML, or is it a file name?" and figure that out.
// Summary:
// Reads XML schema and data into the System.Data.DataSet using the specified
// file.
//
// Parameters:
// fileName:
// The filename (including the path) from which to read.
public XmlReadMode ReadXml(string fileName);
By wrapping the XML in a stringreader or a stream or something, you are calling a different overload, that expects XML instead of a file name.
I have a long javascript in a string and programatically using RegisterClientScriptBlock, I add it to my page.
Is there any way to have the intellisense detect my javascript inside the string?
Code:
string Script0 =
#"
function dummy()
{
}
var PTRValues = new Array();
...
...
..
";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myCustomScriptBlock", Script0, true);
No, you can't get intellisense inside the JS string. The IDE doesn't know this particular string is JS.
If it's long don't put it in the *.cs file. Instead store it in a *.js. If you really want you can load the file into memory at runtime and serve it embedded in the html instead of referenced.
Unfortunately, this is not possible.
The best solution is to make put the code separate .js file, then write the following:
Page.ClientScript.RegisterClientScriptBlock(
GetType(),
"myCustomScriptBlock",
File.ReadAllText(myJSFilePath),
true
);
For optimal performance, you should read it only once, then store in in the cache.
Ok, these guys are getting close...
Don't EVER embed scripts in code. Always embed as resource or for prototyping and develepment use ClientScript to render a <script/> tag and reference a .js file.
There are just too many reasons wny you would not want to embed script in code to list. google it.
What you are after is to render some javascript from the codebehind via ClientScript and you would like design time intellisense support?
Ok,
To get intellisense you will need a .js of some kind. The approach I suggest, to promote maintainability and prevent dupe scripts that can get out of sync is:
create an EMPTY file called myScript.js.
create another script containing your code named myScript-vsdoc.js
mark myScript-vsdoc.js as embedded resource and serve it as and embedded web resource
meanwhile, back in the IDE, add a script tag pointing to myScript.js, which is an EMPTY file
press SHIFT-CTRL-J and bingo, you have intellisense for your embedded script, your embedded script is in a source file that is editable and discoverable and you have no duplication.
That is how i do it.