I have these line of codes : try { string fromDir = file.Substring(0, file.LastIndexOf("\\")); System.IO.Directory.SetCurrentDirectory(fromDir); if (!File.Exists(fileToZip)) { throw new FileNotFoundException("The specified file " + fileToZip + " could not be found. Zipping aborderd"); } FileStream StreamToZip = new FileStream(fileToZip, FileMode.Open, FileAccess.ReadWrite); FileStream ZipFile = File.Create(zippedFile); ZipOutputStream ZipStream = new ZipOutputStream(ZipFile); ZipEntry ZipEntry = new ZipEntry(fileToZip.Substring(fileToZip.LastIndexOf("\\") + 1)); ZipStream.PutNextEntry(ZipEntry); ZipStream.SetLevel(CompressionLevel); if (password != null && !password.Equals(string.Empty)) ZipStream.Password = password; byte[] buffer = new byte[BlockSize]; System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length); ZipStream.Write(buffer, 0, size); try { while (size < StreamToZip.Length) { int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length); ZipStream.Write(buffer, 0, sizeRead); size += sizeRead; } } catch (System.Exception ex) { throw ex; } ZipStream.Finish(); ZipStream.Close(); StreamToZip.Close(); } catch (Exception ex) { throw ex; } The error occurs on this line FileStream ZipFile = File.Create(zippedFile); how am i going to resolve it? thanks
toink toink
Posts
-
The process cannot access the file because it is being used by another process. -
Get list of files from ftpI found an ftp client class from this site and I used the List Function which is as follows: public ArrayList List() { Byte[] bytes = new Byte[512]; string file_list = ""; long bytesgot = 0; int msecs_passed = 0; ArrayList list = new ArrayList(); Connect(); OpenDataSocket(); SendCommand("LIST"); ReadResponse(); //FILIPE MADUREIRA. //Added response 125 switch(response) { case 125: case 150: break; default: CloseDataSocket(); throw new Exception(responseStr); } ConnectDataSocket(); // ####################################### while(data_sock.Available < 1) { System.Threading.Thread.Sleep(50); msecs_passed += 50; // this code is just a fail safe option // so the code doesn't hang if there is // no data comming. if (msecs_passed > (timeout / 10)) { //CloseDataSocket(); //throw new Exception("Timed out waiting on server to respond."); //FILIPE MADUREIRA. //If there are no files to list it gives timeout. //So I wait less time and if no data is received, means that there are no files break;//Maybe there are no files } } while(data_sock.Available > 0) { bytesgot = data_sock.Receive(bytes, bytes.Length, 0); file_list += Encoding.ASCII.GetString(bytes, 0, (int)bytesgot); System.Threading.Thread.Sleep(50); // *shrug*, sometimes there is data comming but it isn't there yet. } CloseDataSocket(); ReadResponse(); if (response != 226) throw new Exception(responseStr); foreach(string f in file_list.Split('\n')) { if (f.Length > 0 && !Regex.Match(f, "^total").Success) list.Add(f.Substring(0, f.Length - 1)); } return list; } But everytime I get files from ftp using this function it includes a date plus other characters plus the name of the file itself. For example: I want to get all the files inside a certain folder in ftp. The filenames of which are Text1.txt, Text2.txt and Text3.txt. Yet when i tried to retrieve its files using this function, it returns 08-29-07 06:42PM 0 Test1.txt 08-29-07 06:42PM 0 Test2.txt 08-29-07 06:42PM 0 Test2.txt My question is, how can i retrieve files from ftp returning only the original filenames which are Text1.txt, Text2.txt and Text3.txt. Thanks
-
RegistryDo you have any c# code that would export registry file? and save it as text format? pls help... I know how to manually export registry file thru registry editor. But how do we do it programmatically using c#? Thanks
-
Retrieving the installed softwares in WMI [modified]how about if we will display the installdate and installlocation using the latter code? or using the registry? if inParam["sValueName"] = keyName is used to get the Displayname, how about the rest of the values? like installdate, softwarepath and the rest of the values?
-
Retrieving the installed softwares in WMI [modified]Hi! How do we retrieve all the installed softwares in WMI? All means all the softwares being installed in the computer. I used win32_Product yet it only retrieves those microsoft softwares and it even displays everything added to that software like an update. The following are the needed information: Softwarename InstallDate SotwarePath AllotedLocationType RegistryPath ExecutableFilename LastUsed TotalUsageDurationMins IsUninstalled IsHotfix IsServicePack isUnauthorized Please help. Thanks. -- modified at 7:18 Thursday 16th August, 2007
-
xml valueyes, i guess so too.. if it has the single "\", it won't accept the string? so how will i go about it?
-
xml valueThis is the error message "An error occurred while parsing EntityName. Line 1, position 160." This is the code upon insertion: elmXML = docXMLFile.CreateElement(element); elmXML.InnerXml = strNewLine.ToString(); docXMLFile.DocumentElement.AppendChild(elmXML) the error occurs on the second line.
-
xml valuewhy do i get an error when trying to insert "PCI\VEN_1106&DEV_3038&SUBSYS_30381849&REV_81\3&267A616A&0&80" as value of my xml element... i'm new to xml. pls help. thanks
-
FtpClientConnectionI just would like to ask for a sample code that really works on Downloading or Receiving files from the FTP. I have these lines of code but seems like it don't work. FtpClientConnection myftpClientConn = null; public frmDbSynch() { InitializeComponent(); } private void btnDBSynch_Click(object sender, EventArgs e) { String[] remoteFileNames = { "myTestFolder", "myFTPFolder" }; String localPath = @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup"; myftpClientConn.ReceiveFiles(remoteFileNames, localPath, true, true); } thanks
-
Error Upon Restoring Transaction LogWhat I am currently doing now is trying to have a backup on database and transaction log on databaseA. But when i tried to restore the transaction log of databaseA to databaseB. It occurred an error. Msg 3154, Level 16, State 4, Line 1 The backup set holds a backup of a database other than the existing 'Test_Remote' database. Msg 3013, Level 16, State 1, Line 1 RESTORE LOG is terminating abnormally. How do i resolve this problem? Such that if i restore transaction log from one database to the other, it won't have an error? Thanks
-
How to create transaction loghow do we backup a transaction log of a certain database? if transaction log doesn't exist yet, how to create transaction log? thanks.
-
editing datagridviewi have a datagridview and a save button. after editing the last cell of the grid and click the save button. the value of the last cell of the datagridview is null. i already set its property to EditOnKeystroke still it returns null to the last cell of the datagrid. thanks
-
checking textboxesi have 6 textboxes in my form how will i check if these textboxes doesn't have same inputted values? i have my own solution but seems to me that my could is quite long. please help thanks
-
using BETWEEN in sql2005I have an sql statement comparing dates in the Where clause. This is my code: [CODE] CONVERT(NVARCHAR, D.Spd_deldateans, 101) between @DATE1 AND @DATE2[/CODE] The problem with the statement, is that, it doesn't show any records when one of the parameters is blank or null. How would it be able to show records giving value only to either of the parameters?
-
DAtaTAble and DataRowI have a monthcalendar control and a combo box control. The current flow of my program is after deselecting a date, it will add a new row in a temporary DataTable. These are the line of codes i am using: Trow= Ttable.NewRow(); Trow[0] = this.monthCalendar1.text; Trow[1] = this.ddlType.SelectedIndex; Ttable.Rows.AddTrow but what if the selected date already exist? what should be done so that it will not add a new row instead update that row? thanks a lot in advance!
-
multiselection of month calendari used the month calendar from the article "ANOTHER MONTH CALENDAR" by Patrick Bohman. got some questions regarding the control: 1. the flow of my project is to select a date, give its corresponding datecode(holiday, special holiday or regular day) then select another date. everytime i choose a another date after the first one, seems i couldn't get the right date selected. i used the DaySelected method. and gets the clicked date by string[] m_daysSelected = e.Days; but seems i couldn't get the right days. how do i do that? and by the way, i have to remember all the selected dates plus its other corresponding data before i get to save the entire selection of the year. is that possible? 2. i have a combo box consisting of different years. each year has different formatted dates. how do i copy the formatted dates of the entire year that chosen from the combo box to the recent year? thanks a lot.
-
button up and downi have 5 groupboxes in one form. each group box has 3 textboxes and two buttons the first textboxes of each groupbox are from a dataset coming from a master lists. for example a productcode. the other two textboxes are the details of the productcode coming from another table from the database which primary code is the productcode the two buttons functions as the following: first button(arrow down) it will display the data from that of the groupbox 2 to the controls of the groupbox 3 and the data from the groupbox 3 to groupbox 2 second button(arrow up) it will transfer the data from that of the groupbox 3 to the controls of the groupbox 2 and the data from the groupbox 2 to groupbox 3 its sort of changing the displayed data either up or down of the other groupboxes
-
button up and downi have a windows application form which has a button up and button down. a groupbox is provided wherein it indicates that it is the first value of the dataset with its corresponding detailed datas. the functionality of the button up is to move that certain data in the 2nd groupbox to groupbox 1... and the button down is to move a certain data in the groupbox 1 to groupbox 2. how is this possible? thanks
-
monthcalendar controli am using a monthcalendar control in my form. and its my first time to use such control. how would i be able to know what year is the current display of the calendar after i clicked the buttons from either side of the navigation button? one of the functionality of the form is also to save holidays on a certain date. and to determine that date to be a holiday, i should change the backcolor of the specific date of the calendar. how would i be able to do such? thanks in advance.
-
printing url [modified]i tried to use these lines of codes: [CODE] public class PrintingExample : System.Windows.Forms.Form { private System.ComponentModel.Container components; private System.Windows.Forms.Button printButton; private Font printFont; private StreamReader streamToPrint; public PrintingExample() : base() { // The Windows Forms Designer requires the following call. InitializeComponent(); } // The Click event is raised when the user clicks the Print button. private void printButton_Click(object sender, EventArgs e) { try { streamToPrint = new StreamReader ("C:\\My Documents\\MyFile.txt"); try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler (this.pd_PrintPage); pd.Print(); } finally { streamToPrint.Close(); } } catch(Exception ex) { MessageBox.Show(ex.Message); } } // The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; string line = null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); // Print each line of the file. while(count < linesPerPage && ((line=streamToPrint.ReadLine()) != null)) { yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } // If more lines exist, print another page. if(line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } // The Windows Forms Designer requires the following procedure. private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.printButton = new System.Windows.Forms.Button(); this.ClientSize = new System.Drawing.Size(504, 381); this.Text = "Print Example"; printButton.ImageAlign = Sy