How To Replace As Little As Possible Of The Existing Code

Apr 15, 2010

I am receiving the contents of a file via ftp. I don't want to go into every detail (unless needed), but I am working with existing code that was using 3rd-party software to get ftp files. I am replacing that with .NET code. But I want to replace as little as possible of the existing code that is not specifically using the 3rd-party s/w. So I am trying to use a class originally written by the author of the code (a former employee).

This is his class constructor:

Code:

Public Sub New(ByVal fileName As String, ByVal content As StreamReader)
Me.FileName = fileName
Me.Content = content
Me.TimeStamp = Date.Now
End Sub

So I need to pass a StreamReader. My problem is how to get one.
In my procedure ReceiveFile(), I execute this code:

Code:

Private Shared Sub ReceiveFile(ByVal sFilename As String, ByRef objMemoryStream As System.IO.MemoryStream)
Try

Dim request As FtpWebRequest = DirectCast(WebRequest.Create("ftp site and folder" & sFilename), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.DownloadFile
request.Credentials = New NetworkCredential("id", "pw")
Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
Dim responseStream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(responseStream)
Dim sFile As String = reader.ReadToEnd
'reader.Close()
' response.Close()
'objMemoryStream = responseStream
Dim objStream As System.IO.MemoryStream
objStream = New System.IO.MemoryStream(Convert.FromBase64String(sFile))
' objMemoryStream = Convert.FromBase64String(sFile)
objMemoryStream = objStream
'Return reader
Catch ex As Exception
Dim i As Integer
i = 10
End Try
End Sub

responseStream is declared as a stream but when I query it in the debugger it says it's an FtpDataStream, after it's set equal to response.GetResponseStream. I want to take that stream and somehow get it into a MemoryStream. I thought I found the solution this morning via Convert.FromBase64String, but when I ran I got an exception saying "Invalid character in a base-64 string", and I think it's because of the newline character in the string. The file that's received contains three lines separated by a newline character.

View 22 Replies


Similar Messages:

Web Forms :: Removing Existing JavaScript And Replace With Code?

Apr 12, 2010

In ASP.NET 4.0 RC2 the Menu Control by default emits Javascript like this:

[Code]....

There should be a feature coming up to disable this, but I think it's not in RC yet. At least it's not working for me.

Now, the problem is, that this Javascript kills my own Menu Javascript (I use an CSS Adapter). Is there a way to overwrite the stuff that comes from the Menu control? Can be a hack, just need something until this is fixed by MS.

View 2 Replies

Web Forms :: Prevent Replace Of Existing File When Uploading Files

May 7, 2015

I am referring [URL] .... how to prevent file to replace when file with same name uploaded, as it replace old one in folder.

View 1 Replies

Web Forms :: Delete Image Folder / Replace Existing Images By Using Update and Display?

May 8, 2010

i want to display images in an asp.net pages.so i used a folder to store the images.again i want to replace the existing images by using update and display.what can i do ,to delete an existing image and insert a new one in ASP.NET

View 4 Replies

Web Forms :: File Upload Control Does Not Replace Overwrite Existing File?

Jun 13, 2012

I hv a file upload control which save files in folder upload_html. When I upload file of same name which already exists upload_html folder it does't replace that file.........

I want that file to be replaced from that folder.............

View 1 Replies

Web Forms :: How To Replace Existing File With Confirmation When Uploading File

Nov 20, 2013

In my asp.net project i have a folder (folder name  "Data").

I upload .pdf file and save the .pdf file in My Data folder.

In same day if i upload same name file then the previous file is overwrite without any message.

So I would like to know, how can i show a message like ("same name file is exit ,Do u want to replace it").

View 1 Replies

How To Replace The Code To CSS

Oct 29, 2010

In a asp.net page, I want to replace the code following to CSS but do not work as expected. How to fix it? (Border-color, ForeColor did note work)

<asp:Label ID="lbl01" runat="server" BorderColor="#B4DAFA" BorderStyle="Solid" BorderWidth="1px" Font-Size="Small" ForeColor="Blue" Style="z-index: 1; left: 3px; top: 10px; position: absolute; height: 14px; width: 325px" Text="Label"></asp:Label>
.LabelStyle
{
clear: left;
float: left;
margin: 5px;
height: 14px;
width: 325px;
Border-Color:#B4DAFA;
Border-Style:Solid;
Border-Width:1px;
Font-Size:Small;
Color:Blue;
}

View 1 Replies

C# - Replace Image In Code Behind

Jul 29, 2010

I have a page, which is called from 2 different functions. For each function, the page has to be display different image. I have 2 images. On the aspx page, code is like this. Please help me out how to display different image for different functions!

View 1 Replies

How To Replace SetExpression Method With Some Other Alternative In Code

Sep 16, 2010

I am trying to freeze my gridview header for last 2 days and got this link and many other links too provided to me on Stackoverflow as well as from googling. This worked fine when i used it on IE 6,7 and under compatibility mode in IE8 but in normal mode, this code is not working.

This line is giving me an error. I want to implement this functionality.

trs[x].style.setExpression("top", "this.parentElement.parentElement.parentElement.scrollTop + 'px'");

On reading comments, I came to know that scrollableTable.js uses setExpression Method which has been depreciated in IE8.

How to replace setExpression method with some other alternative in this code

[code]....

View 3 Replies

Web Forms :: Drop Down List Html Replace Code?

Mar 19, 2010

I tried putting a html replace code into a string which is then placed into a drop down menu. Only problem is it still appears as ² instead of a small 2.

View 5 Replies

Javascript - How To Remove, Replace Or Disable Dynamically-generated ASP.Net Js Code

Jul 16, 2010

I am working with a few .Net 4.0 webforms controls such as the Menu control and while I think it's great that I can now declare the way in which controls are rendered (i.e. as either tables or divs), I can't switch off the automagically-included javascript that manages the hover events for those controls, for example:new Sys.WebForms.Menu({ element: 'NavigationMenu', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: false }This appears at the bottom of every page that owns such a control.

View 1 Replies

WCF / ASMX :: How To Merge Existing Code With Web Services

Sep 26, 2010

i am new to ASP.NET. I am just now learning about all the benefits. I currently have some C# code that receives sensor signals such as distances from a robot and I wish to put that code into web services and into a website, so that if I want to gather some information from the robot i can through the web, as well as send signals back. I haven't found any information yet on how to do this.

I am just looking on how to intergrate the existing C# code I have to a web service

View 1 Replies

Logging Exception Without Changing Existing Code?

May 26, 2010

I have a application, and I want to log exceptions to a file and I don't want to change any code. I just want a component to which I can add my code and it will start logging exceptions. How can I do this?

View 3 Replies

WCF / ASMX :: Generate Web Service In Web Application Using Existing Code?

Jan 15, 2011

Currently I have project in ASP.NET 2.0 and I wanted to implement web services using my existing code.

View 2 Replies

VS 2012 - How To Get Started On Existing Web Service Code Copied Locally

Apr 7, 2014

We have a web service running live. Last week, we pulled the source code down to my machine and successfully built it.

My goal is to become familiar with this code and document it. My problem is that I am not sure how to get it running locally.

First of all, I have to configure it in IIS or something? How do I do that, and is that indeed the right place to begin? I tried creating a consumer in a separate VS solution, and when I said browse for local web services it said "Active Directory Services cannot find the web server."

I tried this link, but got lost when it said "3.Under Visual Studio installed templates, click ASP.NET Web Service." because I don't have that template.

View 4 Replies

Web Forms :: Regex.Replace - How To Replace All In A String

Jun 18, 2010

I need to replace <span> entries in a string to legacy html code because it's going to be used in a report for Crystal Reports. <b> works with Crystal, but the<span>'s do not.

Here's the string which I'm trying to replace: <span style="font-weight: bold">%THIS CAN BE ANY TEXT%</span>. I want to replace it to

<b>%THIS CAN BE ANY TEXT%</b>.

[Code]....

View 5 Replies

Send Sms Code - Replace "&" Character

Feb 21, 2011

I'm writing a send sms code. In that, I've to replace "&" character. Actually if anyone writes &, it sends data before &. Suppose someone writes "I & u" it sends I only. For this I wrote some solutions like this but it doesn't works :

mData = Regex.Replace(mData, "&", "&")
mData = Replace(mData, "&", "%20")

View 3 Replies

Web Forms :: C# Replace " With " Using The Replace Method?

Mar 15, 2011

How do you replace" with" using the replace method?

View 5 Replies

When Add Another Row Its Not Generate New Row That Replace Only Old Row?

Jul 21, 2010

i have done dynamic row create using asp:table control..but the problem is when add another row its not generate new row that replace only old row..whenever i count the tr again its take the count zero..here i want no. of row when user done each
button click..

here codes..

[Code]....

View 3 Replies

Web Forms :: How To Replace URL

Jun 4, 2010

We have developed a web based application for data anlysis. we want to hide its working URL's with some custome url.e.g

[URL]

View 7 Replies

C# - How To Replace Url Value With Regex

Dec 8, 2010

I need a regex or any other solution to replace an id in the middle of a url (not in querystring).
url example - http://localhost:1876/category/6?sortBy=asc&orderBy=Popular

replace - category/6 with category/anotherID -
routing used -
routes.MapRoute(
"categories",
"category/{categoryID}/{categoryName}",
new { controller = "Search", action = "SearchResults", categoryID = "", categoryName = "" }
);

View 1 Replies

Regex.replace [h2] To <h2>?

Aug 25, 2010

I try to replace [h2] to <h2> I use this coding:

string o = "<h2>test</h2>";
o = Regex.Replace(o, "[h2]", "<h2>");
o = Regex.Replace(o, "[/h2]", "</h2>");

But the result after the first regex is:

[<h2><h2>]test[/<h2><h2>]

So that is not what i want.

After the first 1, he should make:

<h2>test[/h2]

Whats wrong?

View 3 Replies

SilverLight Replace ASP?

Aug 30, 2010

i am new to web development and i am learning Asp.net. i was the other day thinking and i came up with this question. i searched the web but all the answers i found were old so my question is , can silverlight4 replace Asp.net? I know this question sounds crazy . but let's think for moment we use ASP.net to talk to a server.to Create files there ,to talk to a database etc. SilverLight can do the same thing ,right? OK,you might say that if I built a web site using SilverLight then not all users out there can access it. but apparently SilverLight supports IE,FireFox Safari and googleChrome so i guess this isn't an issue anymore. so what do you think ,can silverlight replace asp.net?

View 6 Replies

Asp Replace GenericPrincipal?

May 4, 2010

I was wondering what the best way is to replace the genericPrincipal with my own CustomGenericPrincipal. At the moment I have something like this but I aint sure if it's correct.

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
var identity = new CustomIdentity(authTicket);
var principal = new CustomPrincipal(identity);
Context.User = principal;
}
else
{
//Todo: check if this is correct
var genericIdentity = new CustomGenericIdentity();
Context.User = new CustomPrincipal(genericIdentity);
}
}

I need to replace it because I need a Principal that implements my ICustomPrincipal interface because I am doing the following with Ninject:

Bind<ICustomPrincipal>().ToMethod(x => (ICustomPrincipal)HttpContext.Current.User)
.InRequestScope();

So what's the best way to replace the GenericPrincipal?

View 1 Replies

How To Replace The Backslash

Sep 9, 2010

I have an image control with the following string

[URL]

I want to replace string cleartext=imagePath.Replace("","/"); but the backslash causes a problem -- how can I replace the backslash?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved