Web Forms :: Deleting List Item / File - Writing New File With Remaining Items
Dec 23, 2010
Spent ages trying to get this right but am struggling now. I have a list box and textbox, I can happily enter Email addresses into the textbox which are saved into a text file and populated in a list box. I want to be able to select a list item and delete it, along with it's record in my text file. I was going to do it by on the delete list item / button click, it delete's the text file and then writes and a new one with the remaining list items in the list box. Unfortunately it's re-writing the file but either not including the remaining list items. Here's some examples of what I've changed and what populates the text file:
StreamWriter1.WriteLine(Addresses.Items); - System.Web.UI.WebControls.ListItemCollection
StreamWriter1.WriteLine(Addresses.Text); - A blank line?!?
The code is below. The reason I wouldn't allow the user to delete the first list item is because I thought the code was working ok but for some reason putting in a blank line to start with, and if I deleted the line it'd delete all file content. No, I don't know why I thought that either.
[Code]....
where I've gone wrong? I've not actually slept since I woke up at 8am yesterday. It's now 11am... today.
Is there a way that we can change the color (which is defaulted to blue) when the items in the list box are selected? If so can you provide me a sample for it?
There are 25 items in the list. I have selected one item at the time of project creation. But If I edit the project then the list box is showing more selected items instead of one item in the details page.
I have a repeater which binds a set of data. Within this repeater is a column with various controls for updating, deleting, etc. These are image buttons which fire an onclick event such as "DeleteRecord". All this does is fire a stored procedure, passing in the ID of the record to delete from the CommandArgument of the object.
This works wonderfully... except for one rather huge problem. Once you delete a record, if you refresh the page, the record where the first deleted record used to be gets deleted. For instance... if I have 4 records
1 Record1 2 Record2 3 Record3 4 Record4
and I delete record 2... The page reloads with (which is fine):
1 Record1 3 Record3 4 Record4
...if I then hit refresh...
1 Record1 4 Record4
I assume this is because the erroneously deleted object (record3) is now in the same hierarchical place as the old object used to be and .net therefore doesn't know the difference, the page refreshes and fires the onlick event, grabbing out the command argument of the new object and deletes based on the ID as obtained from the commandargument of the new object. This is obviously a huge problem, if a client did this it would destroy data erroneously and I'm at a loss here. Is there any way to stop this from happening? I'm not sure if there is a better way to go about doing things or not. If there isn't, I need some sort of way to tell the page not to execute the event or to cross reference the ID of the object that is intended for deletion against the object itself...
Code below for convenience...
EDIT Wrapped a LinkButton around it because I have some jquery code in here as well which stops the page execution to wait for user confirmation. Pressing "ok" continues page execution.
<asp:LinkButton ID="oDeleteLink" CssClass="oDeleteIcon" CommandName="Delete" CommandArgument='<%# Eval("iAccountID") %>' runat="server"> <asp:ImageButton ImageUrl="/files/system/icons/trash-steel-16.png" ToolTip="Delete This Account" AlternateText="Delete" ID="oDeleteIcon" runat="server" /> </asp:LinkButton> protected void oAccounts_ItemCommand(Object Sender, RepeaterCommandEventArgs e) { if (e.CommandName == "Delete") { int ID = e.CommandArgument.ToString().Numeric(); db.SPs.SpDeleteAccount(ID).Execute(); UI.Confirm(uiBroadcast, "Account has been deleted", "300px"); BindAccounts(); } }
I have one gridview in that i have three columns "FileName" "Open" and "Delte" if user Opens clicks on open Pdf file opens in new window that time if user clicks on Delete Button then its giving Error that "Process is using by Some one" ...
Based on this piece of code, I want to do exactly like this demonstration. However, correct me if I'm wrong but if two or more users somehow simultaneously access the web page at the same precise nanosecond in time, then wouldn't we have a race condition? So is this piece of code valid? How would I correct this to make it thread safe?
I am using more than one files to read and write to the server. Suppose during writing or reading any of files gets error the already stored files need to be rollback or removed from storing.So that the user agin try to write without error. Simply the all of the files need to be stored into the server without error, of error occurs to any of file none of files need to be read/write
I am trying to create and write a file on a remote server using the below code:
[Code]....
but i am running into issues and getting errors. Below are some tries i have given. My IIS settings are 'Anonymous Access' checked and also 'Integrated windows authentication' checked.
a. As i understand asp.net site would run using ASPNET account, i tried giving full permission to ASPNET account to the folder on the remote server (where i want to drop the file). But i am getting this error - "Logon failure: unknown user name or bad password"
b. The other thing i tried is giving full permissions to 'Everyone' to the remote server folder. But i get the same error as above. But when in my web.config i enable impersonation by using: [Code]....
then the error goes away and everything works fine as expected. The file gets dropped to the network share.
why the scenario (a) doesn't work because that should work as if i give ASPNET account full access to the folder, and my website is running under the same account, then it should work.
Also, in the scenario (b), i believe it is using my domain account, as the impersonation is true without specifying any username and password and also the remote server folder has Everyone access to full control. BUT, as a security breach, i cannot use Everyone account to the remote folder. In that case, how can i make this working.
I was also thinking if i can use the virtual directory as the path to the remote folder, something like http://domain.com/remotefolder but dont know how can i use this approach. Can someone pls share some sample code and the configuration.
I'm making an application which takes image from user upload it to server and then perform any image processing like to convert to gray or invert etc.
My problem is this when i did the process on image to gray it or invert then how to write this new file on server or is there any other way so that i would be able to show this (new) image to user and make it downloadable?
In my application i want to share one .txt for read and write among no. of users. in Button click i m writing data in that file and in tick event of Timer i m reading that file, In tick event i m reading that file based on file based cachin means if file have been changed then only i m reading that file but when i have put m application i IIS then i m not able to get updated file.
i want to maintain a log of the visitors for a website.. the number of visitors is fix approximate (800), but i have to maintain the record of each visit page wise like page Id, time visited, user id. i am doing it using a database as it was .
i was asked to use a insert query on every page ,(ie each time user visits a page write the log to database), but i dint like the idea.. of making server trips every time the user visits a page and also we have a seperate database server. I had a idea of using XML.. but which is the best way performance wise writing a log in Xml file or insert query in database?
I have the following subroutine in an asp.net application class. The subroutine writes data to a text file upon application login. My question is that if this function was called at the same time by two different users would it cause any kind of error. Is there a need for a try catch?
Public Shared Sub writeToLogFile(ByVal UserName As String) Dim strLogMessage As String = String.Empty Dim strLogFile As String = System.Web.HttpContext.Current.Server.MapPath("~/Log.txt") Dim swLog As StreamWriter strLogMessage = DateTime.Now.ToShortDateString().ToString() " ==> " & UserName If Not File.Exists(strLogFile) Then swLog = New StreamWriter(strLogFile) Else swLog = File.AppendText(strLogFile) End If swLog.WriteLine(strLogMessage) swLog.WriteLine() swLog.Close() End Sub
I keep getting this error when trying to Run or Build my ASP Project. A few details:
I migrated this project from VS 2003 to VS 2008 (C#) It works fine when I successfully compiled it and deployed onto server.I have Plenty of free diskspace available.I have 4 GB Ram and Windows XP So each time I try to build this project, I get the following error.
Error 57 Unexpected error writing metadata to file 'C:InetpubwwwrootProject.IntranetobjTestProject.Intranet.dll' -- 'Not enough storage is available to complete this operation. 'Project.Intranet
I am having an issue where if I add something to an aspx file, such as adding "<asp:HyperLink ID="HyperLink1"...", the item is not recognized in the associated vb file and I get "Name 'HyperLInk1' is not declared". Nothing I've tried seems to work, and the only way I can get it to work is to delete the files from the project, then re-add them back in as a new web form. Then it works.
why this is happening, and how I get it to recognize when I add things to an asp file? Of course I save the files and rebuild the web site, and that doesn't work.
I'm fairly new at writing c# with asp.net and thought I'd give writing a custom class for a single file uploader, but Im a bit stuck with it. I get build errors with a few of the items, here's my code:
i have a folder in soultion explore that in folder there are some xml file but when write data in c# in xml file,error Access to the path 'E:YavariTCMS-v3TCMSTCMSMDFXMLXMLFile1.xml' is denied. every i remove propertice readeonly from xml or folder that contain xml file ,next tim reade onl true
I am trying to write some lines at runtime to a text file using streamwriter, but i have to allow only 100 lines to be written to that file, if 101 line is supposed to be written to that file than first line of the file must get discarded/deleted and file must allow writing the 101 line so the file will actually always contain only 100 lines.
I have an object on the webpage that I normally will attach a source to. When doing that as in the code below it works fine.But if I have a empty string for setSrc1, then the webpage shows a message in the left down corner that:
"1 items remaining" Waiting for...
How would it be possible to not have this message if no src is set to the Object1 ?
i have table data which i am currently writing to an excel file, but i need to be able to securely password protect the file. Ive been told excel passwords are easy to break, so is there another file type which i can dynamically write to and password protect for emailing elsewhere (and requiring receiver to type password in to access it)?
i have write data from db to .txt file,where db have large amount data,i need to wite data into file, if some error occure, then reInitiated that file and write data again without stop process.that is Continuous calling same process