|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I'm trying to get the list of allocated ranges for a sparse file on Windows 10 from a C# program. DeviceIOControl requires an array of FILE_ALLOCATED_RANGE_BUFFER structures as the output buffer. I just can't seem to get the correct way of passing these. So far I have....
public static bool GetSparseRange(SafeFileHandle hdrive, in FILE_ALLOCATED_RANGE_BUFFER query, ref FILE_ALLOCATED_RANGE_BUFFER[] response, int count)
{
int nInBufferSize = (int)Marshal.SizeOf(typeof(FILE_ALLOCATED_RANGE_BUFFER));
IntPtr lpInBuffer = Marshal.AllocHGlobal(nInBufferSize);
Marshal.StructureToPtr(query, lpInBuffer, true);
uint bytesread=0;
IntPtr[] ptrArr = new IntPtr[count];
for (int i = 0; i < count; ++i)
{
ptrArr[i] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FILE_ALLOCATED_RANGE_BUFFER)));
Marshal.StructureToPtr(response[i], ptrArr[i], true);
}
bool rc = DeviceIoControl(
hdrive, // device to be queried
(uint)EIOControlCode.FsctlQueryAllocatedRanges, // operation to perform
lpInBuffer, (uint)nInBufferSize, // input buffer
ptrArr, (uint)(nInBufferSize * count)), // output buffer
ref bytesread, // # bytes returned
IntPtr.Zero); // synchronous I/O
// Get the last error and display it.
int error = Marshal.GetLastWin32Error();
for (int j = 0; j < count / nInBufferSize; ++j)
{
if (j < bytesread / nInBufferSize)
Marshal.PtrToStructure(ptrArr[j], response[j]);
Marshal.FreeHGlobal(ptrArr[j]);
}
Marshal.FreeHGlobal(lpInBuffer);
return rc;
}
However this return rc=false, byteread=0 and error=5.
Can anyone suggest the correct way to do this?
Thanks
|
|
|
|
|
Hi, folks.
I created a user control with some properties and methods and used it in a Forms project where it appears many times. It's working fine.
But now I decided to improve some characteristics and I eliminated some properties and added some.
The problem is that the forms where this control appears show errors and it' very difficult to open the form. After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted.
What is the best way to substitute a control under these circumstances?
I use C# in Visual Studio 2019.
Thanks.
|
|
|
|
|
The problem is probably that as you say:
Quote: I eliminated some properties and added some.
If any of the classes that use your control are referencing those properties, the new version will just not work: the properties no longer exist.
The proper way to do that is to depreciate the properties, not remove them: that way they can still be used but there is a warning that they shouldn't be used in new projects.
That is documentation only, however - for later versions, you can make them actually obsolete: ObsoleteAttribute Class (System) | Microsoft Docs[^] but you should allow a good time for people to migrate to the newer version before that happens.
Often, a more developer friendly way to do this with drastic changes is to end support for the existing version, and develop a new version for future projects.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Make the properties obsolete? I'll read more about.
Thanks.
|
|
|
|
|
You're welcome!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Member 14792393 wrote: I decided to improve some characteristics and I eliminated some properties and added some. A key question is what you did to the Forms that had instances of the UserControl that used the removed Properties: of course any attempted use/access of/to removed "anything" results in compile errors.Member 14792393 wrote: After I open the form I removed the old control and tried to add the new version, but it appears that only the old version is accepted This just doesn't make sense: did you edit the form code to remove any code that used the UserControl instance, and, then, re-build the Project/Solution? Did you re-build the solution after adding the new version of the UserControl?
There is (imho) a defect in Visual Studio that has never been fixed: you can modify a UserControl ... for example, add some new Control to it ... and, the change doesn't appear in currently open design-time Form Windows even after you re-build the solution. However, if you close the designer window, and re-open it: the view has been updated.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
"did you edit the form code to remove any code that used the UserControl instance, and, then, re-build the Project/Solution? Did you re-build the solution after adding the new version of the UserControl?"
Yes, but the application is too big and has many instances of the control.
What I intend to do now is to rename the new version of the control and add it to the project. Then I open each form, erase the old version and insert the new version. After that I can remove the old version. It's a hard job, but I think it's the only way.
What do you think?
Thanks.
|
|
|
|
|
If you really have removed Properties you have to realize that those Properties perhaps are used by the Designer-Script of your Form.
So you must open the DesignerScript of your Form, find those part which assignes the Properties of this Control and delete those Assignments which are not more existent ...
|
|
|
|
|
good point from a slightly different angle
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Maybe you're right. I'll take a look.
Thanks.
|
|
|
|
|
you will see it ...
And you are welcome ...
|
|
|
|
|
Here is some sample data i have been provided using json post
{
"PropertyInfos": [
{
"Identification": {
"IDValue": "102"
},
"PropertyName": "Casa Bella",
"ManagementCompany": {
"ManagementCompanyName": "ACME Trusts",
"Identification": {
"IDValue": "2"
}
},
"Address": {
"Address": "425 Slopestyle Skies Se",
"City": "Lincoln",
"State": "NE",
"PostalCode": "67123",
"Email": "test@example.com"
}
},
{
"Identification": {
"IDValue": "20"
},
"PropertyName": "Tall Tower",
"ManagementCompany": {
"ManagementCompanyName": "ACME Trusts",
"Identification": {
"IDValue": "2"
}
},
"Address": {
"Address": "789 Steele Street",
"City": "Denver",
"State": "CO",
"PostalCode": "80206",
"Email": "tall.tower@example.com"
}
},
{
"Identification": {
"IDValue": "92"
},
"PropertyName": "Z Emerson",
"ManagementCompany": {
"ManagementCompanyName": "ACME Trusts",
"Identification": {
"IDValue": "2"
}
},
"Address": {
"Address": "2199 112th St S",
"City": "Chicago",
"State": "IL",
"PostalCode": "60444",
"Email": "test@example.com"
}
}
]
}
How can I convert this into a list or dictionary so i can then work with each of the entries and import them into my system using c#. if they were in a list or dictionary i would be able to go through the list and do what i need with each data entry. I am very new when it comes to working with JSON api and what not. Any help or pointers in the right direction would be awesome. Thank you guys! 
|
|
|
|
|
Why not do what JSON is meant to do and convert it to classes? You can then use the classes directly in your code instead of trying to manually process the hierarchical data.
It's even easy to do: paste the JSON into your C# app in VS using "Paste special...Paste JSON as Classes" and VS will create the classes it represents for you. You can then use a JSON reader (I use Newtonsoft JSON.NET[^]) to process the JSON string and give you the filled out class data.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
 Lol im completely new to JSON so sorry for not knowing exactly what its supposed to do Heres the code to convert it to classes. I used quicktype.io to help me
<pre>// <auto-generated />
//
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using quicktype;
//
// var welcome = Welcome.FromJson(jsonString);
namespace quicktype
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class Welcome
{
[JsonProperty("PropertyInfos")]
public List<PropertyInfo> PropertyInfos { get; set; }
}
public partial class PropertyInfo
{
[JsonProperty("Identification")]
public Identification Identification { get; set; }
[JsonProperty("PropertyName")]
public string PropertyName { get; set; }
[JsonProperty("ManagementCompany")]
public ManagementCompany ManagementCompany { get; set; }
[JsonProperty("Address")]
public Address Address { get; set; }
}
public partial class Address
{
[JsonProperty("Address")]
public string AddressAddress { get; set; }
[JsonProperty("City")]
public string City { get; set; }
[JsonProperty("State")]
public string State { get; set; }
[JsonProperty("PostalCode")]
[JsonConverter(typeof(ParseStringConverter))]
public long PostalCode { get; set; }
[JsonProperty("Email")]
public string Email { get; set; }
}
public partial class Identification
{
[JsonProperty("IDValue")]
[JsonConverter(typeof(ParseStringConverter))]
public long IdValue { get; set; }
}
public partial class ManagementCompany
{
[JsonProperty("ManagementCompanyName")]
public string ManagementCompanyName { get; set; }
[JsonProperty("Identification")]
public Identification Identification { get; set; }
}
public partial class Welcome
{
public static Welcome FromJson(string json) => JsonConvert.DeserializeObject<Welcome>(json, quicktype.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Welcome self) => JsonConvert.SerializeObject(self, quicktype.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString());
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}
Now ive created a class in c# where i can access these classes. How do i get JSON to put my POST data into these classes. Or are you able to point me to a video, guide, etc that could help me learn this
|
|
|
|
|
As I said, I prefer Newtonsoft, so follow the link in my original response, and it'll show you how to deserialize it. It's only one line of code!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
There is a requirement to send and receive data over TCP/IP with a Fiscal (tax) device which acts as a gateway to the Tax authority server.
The application runs on c#.
Can anyone suggest suitable c# libraries which can be used for this purpose?
The data is to be packaged in JSON format.
Any help would be very much appreciated.
|
|
|
|
|
|
ICARUS999 wrote: There is a requirement to send and receive data over TCP/IP with a Fiscal (tax) device which acts as a gateway to the Tax authority server. Have you researched the API, and/or requirements/protocols/syntax/authorization, for interop with the specific device you describe ?
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
hello
have searched google a lot but couldn't find any.
i am trying to create a report in visual studio 2019. data is coming from SQL server and using reportViewer1 to print the report.
can someone show me a good tutorial on it.
|
|
|
|
|
The reportViewer control has print controls on it. Did you try those?
|
|
|
|
|
i can't get to show data in the report.
i even tried with report wizard too.
first created a dataset then in the dataset created data table.
after this report filed headers are added to the report and when i run report shows only header names but no data.
|
|
|
|
|
It's been a long time since I have used it so I don't remember any specifics but it sounds like either the sql is not being executed or it is and it's not returning data.
Try using Sql profiler on your database to see if any sql is being executed.
|
|
|
|
|
|