how to generate a xml file for my VB project? - vb6

We are created a application using VB.So,Whenever i click the project exe file i want to create a xml file and store some config.details for my application for further needs.
Now i created that xml file in my local drive(d:\appConfig\config.xml).But we have to handover only our project exe to client.So,Client may have the D drive or not.So, How do i create the config xml file in common to all client machine.
This is my code:
Dim doc As XmlDocument = New XmlDocument
doc.Load("D:\appConfig\trial.xml")
Dim newElem As XmlElement
newElem = doc.CreateNode(XmlNodeType.Element, "file", "testing")
newElem.SetAttribute("filename", filenameenc)
newElem.SetAttribute("expdate", g)
Dim root As XmlElement = doc.DocumentElement
root.AppendChild(newElem)
doc.Save("D:\appConfig\trial.xml")
Is there any way to create the config xml?
Please guide me to get out of this issue?

Related

Add a text file as a resource in Visual Studio 2022

I am creating a WebView2 app (WPF using C#) and I want to have a index.html file as a resource.
The idea is that when I create a project, a new folder is created.
This folder will contain an index.html file for the WebView control to load.
The index.html file then points to project specific data as relative paths.
I would like to have a file embedded in my resources that I can use at runtime like this
`void newProject()
{
string strHTML = /** code to read from resource file **/
createFile(projDir + "\\index.html") /** code to create a new file **/
/** code to write strHTML string to new index.html file **/
}
`
I know I can create a static string to do this, but editing is easier if I have the resource as a file.
Thanks in advance.
D
Update:
I put the file into the resources. Then, I added this code
var assem = Assembly.GetExecutingAssembly();
String[] resources = assem.GetManifestResourceNames();
html = assem.GetManifestResourceStream("index.html")
The resources string array always has two elements regardless of what I have in my resources file.
"WebView2Testing.g.resources"
"WebView2Testing.Properties.Resources.resources"
which has nothing to do with my file.
GetManifestResourceStream("index.html") returns null.
FYI I am using .net6 and WPF Windows app.
Any more ideas?

Not a valid resource name of assembly

I'm using Xamarin Studio and GTK#(.NET). I have the following problem:
I've made an app, and I need to(dinamically) download web images(favicons) and display them in a Gtk.Image widget. When I try to do this, I get the following error:
System.ArgumentException: 'myfile.ico' is not a valid resource name of assembly 'myApp, Version=1.0.6742.24722, Culture=neutral, PublicKeyToken=null'.
at at Gdk.PixbufLoader.InitFromAssemblyResource(Assembly assembly, String resource)
at at Gdk.PixbufLoader..ctor(Assembly assembly, String resource)
at at Gdk.Pixbuf..ctor(Assembly assembly, String resource)
at at Gdk.Pixbuf.LoadFromResource(String resource)
It works if i add the favicon, after download,in the resource folder, BUT I need to make this dinamically(if I add a new site, I want to see it's icon there..).
The code:
using (WebClient client = new WebClient())
{
client.DownloadFile(new Uri("https://google.com/favicon.ico",
Directory.GetCurrentDirectory() + "\..\..\Res\google.ico");
}
faviconImage.Pixbuf = Gdk.Pixbuf.LoadFromResource("myApp.Res.myfile.ico");
The image is in the folder(i can see it, it's everything ok) but i cannot use it if i don't include it(manually) in the resource folder....
Please help me :'(
Pixbuf.LoadFromResource only loads image data from an embedded assembly resource. You can not add resources to assemblies after they are created.
To create a Pixbuf from a file, use one the its .ator that supports either a file path to the image or one that uses a file stream.
Something like:
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "myDownloadIcon.ico");
var newPixBuf = new PixBuf(filePath):
faviconImage.Pixbuf = newPixBuf;

WIndows file/ folder permission using vb.net

I can set file/ folder restriction using the given code.
Imports System.Security.AccessControl
Dim FolderPath As String = "C:\TestingFolder" 'Specify the folder here
Dim UserAccount As String = "MYDOMAIN\someuser" 'Specify the user here
Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
Dim FolderAcl As New DirectorySecurity
FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
FolderAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
FolderInfo.SetAccessControl(FolderAcl)
My aim is to set the permission using the code in a way that only my application can change the read/write access to the file/folder. No one can change the permission except my vb.net program.
My goal is to write a security application which will ask password to access the program, and the program will be able to grant access(read/write/modify) to the user.

How to read Asset Files using VS & Monodroid

I've been trying to implement this example using C# and Monodroid, but am having difficulties reading and writing an Asset file:
http://docs.xamarin.com/android/advanced_topics/using_android_assets
I am using the emulator, not a device.
First of all, I am having trouble finding the namespace for Assets.Open. What I ultimately found was
const string lfn = MyAssetFile.txt;
System.IO.StreamReader(Android.Content.Res.Resources.System.Assets.Open(lfn);
Is this the correct namespace?
Second of all, my Asset file is marked as AndroidAsset and "Copy Always" in the VS "Properties" pane, but my attempts to read the file always fail (File Not Found) using this statement:
string settings = "";
using (StreamReader sr = new System.IO.StreamReader (Android.Content.Res.Resources.System.Assets.Open(lfn))) settings = sr.ReadToEnd();
Do I have my VS settings wrong so that the asset file not being copied onto the emulator, or is it being copied OK but my code to open/read it is wrong?
You must use:
const string lfn = "MyAssetFile.txt";
string settings = string.Empty;
// context could be ApplicationContext, Activity or
// any other object of type Context
using (var input = context.Assets.Open(lfn))
using (StreamReader sr = new System.IO.StreamReader(input))
{
settings = sr.ReadToEnd();
}
If I remember correctly, as I haven't got an IDE at the moment, Android.Content.Res.Resources.System.Assets references the Android assets not your project assets. You want to use your projects assets so you need to use the AssetManager from your Activities or Contexts.
For example: the Activity class has a property called Assets. This is what you use. OR you use a View's Context.Assets property.
Or just simply add at the top:
using System.IO;
and it will work.
Xamarin team forget sometimes to mention using stuff.

How to create a object of java class in excel vba

i have a java class..i have registered in my system(it has shown the message as
registed successfully)..but when i try to create an object(the code is as below)
It is throwing error as module not found..do i have set the path.if yes how..
Dim conn
set conn = createObject("Main")
Main is the java class which is in C:\windows\java\trustlib
Please help me out..i am new to excel vba
See this description of CreateObject. Your code should look like this
Dim conn
Set conn = CreateObject("<server>.Main")
Where <server> is the name of the application providing the object.

Resources