|
ok, my problem is this, i can compress/uncompress file using the lib system.io.compression, but i dont know how to do this using into multivolumen file, i mean i want to compress a large file into several small file. how can i do this using .net library?
|
|
|
|
|
These smaller files, do they have to conform to a standard or can they just represent a large chunk of binary split into chunks? Also, what framework are you using (2,3,4 etc.) as they've added quit a bit to that namespace of late.
Regards,
Rob Philpott.
|
|
|
|
|
easy i want to do the split into volumen size that winrar do. for example i have a file that have 200mb and i want to compress it into two file of 100mb.
|
|
|
|
|
Hmm. OK, on the assumption that you are compressing one file, and that the separate chunk files are not expected to interop with things like WinZip or WinRar it would be fairly straight forward.
- Open the source file with a FileStream
- Chain a DeflateStream onto the filestream (just pass in constructor)
- Read from the deflate stream the number of bytes you want in your chunks (into byte array)
- Write entire byte array to individual file.
- Goto 3 (until end of filestream).
Going the other way is a bit more tricky, as you can't really create one stream from a set of files, but works in a similar fashion.
Regards,
Rob Philpott.
|
|
|
|
|
finally someone, thanks i'll try waht you tell me. i dont know what its DeflateStream but i'll make a search on the net for it. if you any example i'll thanksful too.
and yes am compressing only one file.
thanks
|
|
|
|
|
|
that class is what i want to use, but i don't know how to split a file in several file. someone can tell me how using zip class can split a single file into several file?
thanks
|
|
|
|
|
Follow the link I gave you and read the documentation.
|
|
|
|
|
look i had read the link you gave to me, but there i cant find how to split a file while compress it.
Zip class methods:
CreateFromDirectory(String, String)
CreateFromDirectory(String, String, CompressionLevel, Boolean)
CreateFromDirectory(String, String, CompressionLevel, Boolean, Encoding)
there is not a parameter where i can specify the volumen's size.
i don't know if cant explain clearly what i want but i'll try one more time.
i know how to zip/unzip using .net zip class, but i don't know how using .Net library split volume zip files. someone can just tell me how to do it, just a simply code, it cant be more than 3 line but i can find the parameter to do that.
thanks again.
|
|
|
|
|
jackie.3981 wrote: how to split a file while compress it. Sorry, but I do not understand. Why would you want to split a file at the same time as you compress it?
|
|
|
|
|
OK, let me explain again.
i made a soft that get data for a database and make and XML. that XML sometimes get more than 150mb and so but i need to send the XML by email. sometime with just a compression it fix by email but sometimes not, so i need that when the size is bigger that for example 100mb, make an split the zip file. its the same if you get the file and compress it with winrar using the option "split to volumes, size" but i want to do that in c# using if its possible zip class.
|
|
|
|
|
Then you probably need to split the file into a set of new files and then zip those 'subfiles' into an archive. Or, maybe split the file and compress each part separately before emailing it to the recipient.
|
|
|
|
|
i found this code in stackoverflow:
int SegmentsCreated ;
using (ZipFile zip = new ZipFile())
{
zip.UseUnicode= true;
zip.AddDirectory(@"MyDocuments\ProjectX");
zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G") ;
zip.MaxOutputSegmentSize = 100*1024 ;
zip.Save("MyFiles.zip");
SegmentsCreated = zip.NumberOfSegmentsForMostRecentSave ;
}
the line in bold make what i want but when i copy this code into VS get errors that i don't know how to fix it, so i try to get help to do this maybe in other way. I've made it using 7zip lib but i don't want to use external lib, i want to use .net library.
thanks.
|
|
|
|
|
jackie.3981 wrote: when i copy this code into VS get errors that i don't know how to fix Well you need to tell us what those errors are. Alternatively you could go back to SO and ask the person who wrote the code.
|
|
|
|
|
error:
CS1674 'ZipFile': type used in a using statement must be implicitly convertible to 'System.IDisposable' ConsoleApplication3
|
|
|
|
|
jackie.3981 wrote: that get data for a database There is your solution, work out the max no records before you exceed your size limit and make multiple queries to the database. Save each query to a separate file and zip each file into s series.
No splitting, no stitching together of zipped files. You will need to manage the merge of the data in the series at the other end but that is trivial.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
My sample as follows:
Now i use Func<> can output 1 param, but i need 3 param output, how can i do it?
Func<int,double> call = y => fun(y, z);
//i need output o1,o2, like y=>fun(y,z,out o1,out o2) ?
ThreadStart start = () => fun1(x, call);
Thread th = new Thread(start);
|
|
|
|
|
Use a lambda:
private void DoThread(int i, out int j, out int k)
{
j = i * 2;
k = i * 3;
}
...
int x = -1;
int y = -1;
Thread start = new Thread(() => DoThread(6, out x, out y));
start.Start();
Thread.Sleep(1000);
Console.WriteLine("{0},{1}", x, y);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
oh, DoThread function i want to transfer to Thread as a var, your sample is call immidiately.
ThreadO th_o = new ThreadO(x => c( x, n,out F)); //this is Func<>,but i also want to out F
Thread th = new Thread(new ThreadStart(th_o.Cons_Mult));
th.Start();
private double c(double x,double n,out double F)
{
}
class ThreadO
{
public ThreadO(Func<double[], double,="" double=""> fun1)
{
...
}
}
|
|
|
|
|
If you can handle one parameter, you can handle multiple; encapsulate all three items in a class, and set an instance of that new class as your parameter.
class MyClass
{
public string o1;
public object o2;
public int y { get; set; }
public int z { get; set; }
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes,haha, you are right, but i want my code simplex and efficient, so i hope no more class, only several variable can solve it.
Func<> can output one param, but i want more output param. ,i don't know how to do it.
how can i use delegate to define multi-output delegate ?
|
|
|
|
|
smallkubi wrote: i want my code simplex and efficient, so i hope no more class How would boxing the result be ineffcient? And no, that was not complex.
smallkubi wrote: how can i use delegate to define multi-output delegate ? You can return an struct or object, you can use out parameters. Or even a callback that gets called for each output-variable
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I think what you want here is a way to "compose" a Func that you can use later
public struct TestStruct
{
int X;
int Y;
public TestStruct(int x, int y)
{
X = x;
Y = y;
}
}
private Func<int, int, TestStruct> TestFunc = (x, y) =>
{
return new TestStruct(x * 4, y * 5);
};
private TestStruct testStruct1;
testStruct1 = TestFunc(100, 200);
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
I use Interop.RSIOPC.dll to connect via "OPC" a c# code with the PLC. I browse between the tags in the PLC memory and to do that I am using some functions. Browsing is mainly "moveDown(branch name)" or "MoveUp()". This is working. But if I need to jump staright to a branch I have to use MoveTo(ref System.Array). The array is created typeof string. At runtime MoveTo returns with a generic error and after many test my guess is that problem is related to the fact that I am using managed objects while the dll operated unmanaged.
Many thanks in advance for any help.
Regards
Roberto
I add here some more details:
my c# code :
System.Array branches;
branches = System.Array.CreateInstance(typeof(string),1);
branches.Initialize();
branches.SetValue("SLC_MODBUS_BASIC", 0); //name of the branch I need to move to
MyOpcBrowserName.MoveTo(ref branches); //pass the System.Array by ref as requested by the dll
This generate the unmanaged exception "Error HRESULT E_FAIL has been returned from a call to a COM component."
Error code -2147467259
Source "Interop.RsiOPCAuto" " at RsiOPCAuto.OPCBrowser.MoveTo(Array& Branches)\r\n at ... my code..
Here below the code from OPC foundation
OPCBrowser.cpp
// (c) Copyright 1998 The OPC Foundation
.
.
.
#include "stdafx.h"
#include "OPCBrowser.h"
.
.
.
// OPCBrowser::MoveTo method
STDMETHODIMP COPCBrowserImpl::MoveTo( SAFEARRAY ** ppBranches )
{
if(*ppBranches == NULL)
return E_INVALIDARG;
// Clear out the list
ClearNames();
HRESULT hr = S_OK;
LONG lBound=0;
LONG uBound=0;
// ServerHandles
hr = SafeArrayGetLBound(*ppBranches, 1, &lBound);
if( FAILED(hr) )
return hr;
hr = SafeArrayGetUBound(*ppBranches, 1, &uBound);
if( FAILED(hr) )
return hr;
hr = MoveToRoot();
if( FAILED(hr) )
return hr;
for( LONG index=lBound; index<=uBound; index++ )
{
BSTR Branch;
hr = SafeArrayGetElement(*ppBranches, &index, &Branch);
if( FAILED(hr) )
return hr;
if(*Branch != 0 )
{
hr = m_pOPCBrowser->ChangeBrowsePosition( OPC_BROWSE_DOWN, Branch );
SysFreeString( Branch );
if( FAILED(hr) )
return hr;
}
}
return hr;
}
Thank you in any case
Roberto 
modified 22-Dec-15 4:25am.
|
|
|
|
|
Hello can someone help me with some exercises? The questions are rather long so i cant post them here.
If someone is patient enough to check my code please leave a message
|
|
|
|